After all the hard work you've done to complete your web game project, it wouldn't be fair if it ended up generating traffic and income for 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 prevent your web game from being pirated, perform the following steps:
// file: BlockAccess using UnityEngine; using System.Collections; public class BlockAccess : MonoBehaviour { public bool checkDomain = true; public bool fullURL = true; public string[] DomainList; public string message; private bool illegalCopy = true; private void Start(){ print (Application.absoluteURL); if (Application.isWebPlayer && checkDomain){ int i = 0; for (i = 0; i < DomainList.Length; i++){ if (Application.absoluteURL == DomainList[i]){ illegalCopy = false; }else if (Application.absoluteURL.Contains(DomainList[i]) && !fullURL){ illegalCopy = false; } } } } private void OnGUI() { if (illegalCopy) GUI.Label(new Rect(Screen.width * 0.5f - 200, Screen.height * 0.5f - 10, 400, 32), message); else Application.LoadLevel(Application.loadedLevel + 1); } }
This is not a valid copy of the game
in the Message field, as shown in the following screenshot: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 screen.
The following 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 your game won't be stolen and published under a URL such as www.stolenGames.com/yourgame.html?www.myDomain.com
.
3.145.178.151