After all the hard work you've had to go through to complete your web game project, it wouldn't be fair if it ended up generating traffic and income on someone else's website. In this recipe, we will create a script that prevents the main game menu from showing up unless it's hosted by an authorized server.
To test this recipe, you will need access to a webspace provider where you can host the game.
To prevent your web game from being pirated, follow these steps:
Text – warning
. Then, from the Text component in the Inspector, change its text field to Getting Info. Please wait
.Text – warning
game object:using UnityEngine; using System.Collections; using UnityEngine.UI; public class BlockAccess : MonoBehaviour { public bool checkDomain = true; public bool fullURL = true; public string[] domainList; public string warning; private void Start(){ Text scoreText = GetComponent<Text>(); bool illegalCopy = true; if (Application.isEditor) illegalCopy = false; if (Application.isWebPlayer && checkDomain){ for (int i = 0; i < domainList.Length; i++){ if (Application.absoluteURL == domainList[i]){ illegalCopy = false; }else if (Application.absoluteURL.Contains(domainList[i]) && !fullURL){ illegalCopy = false; } } } if (illegalCopy) scoreText.text = warning; else Application.LoadLevel(Application.loadedLevel + 1); } }
1
and fill out Element 0 with the complete URL for your game. Type in the sentence This is not a valid copy of the game
in the Message field, as shown in the following screenshot. You might have to change the paragraph's Horizontal Overflow to Overflow.menu
.nextLevel
.As soon as the scene starts, the script compares the actual URL of the .unity3d
file to the ones listed in the Block Access
component. If they don't match, the next level in the build is not loaded and a message appears on the screen. If they do match, the line of code Application.LoadLevel(Application.loadedLevel + 1)
will load the next scene from the build list.
Here is some information on how to fine tune and customize this recipe.
Your game will be more secure if you fill out the domain list with complete URLs (such as http://www.myDomain.com/unitygame/game.unity3d). In fact, it's recommended that you leave the Full URL option selected so that your game won't be stolen and published under a URL such as www.stolenGames.com/yourgame.html?www.myDomain.com
.
3.144.26.138