Preventing your game from running on unknown servers
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.
Getting ready
To test this recipe, you will need access to a webspace provider where you can host the game.
How to do it...
To prevent your web game from being pirated, follow these steps:
- From the Hierarchy view, use the Create drop-down menu to create a UI Text GameObject (Create | UI | Text). Name it
Text – warning
. Then, from the Text component in the Inspector, change its text field toGetting Info. Please wait
. - Add the following C# script to the
Text – warning
game object:using UnityEngine; using System.Collections; using UnityEngine.UI; public class BlockAccess : MonoBehaviour { public bool checkDomain...