Forum rules - please read before posting.

Script for sitelock with Unity Web Player

Hi,

Here's the script to sitelock your game to the domains of your choice with Unity Web Player only.

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public class SiteLock : MonoBehaviour {
public string[] domains = { "yoursite.com", "anothersite.com" };
public string redirectUrl = "http://yoursite.com/";
void Awake () {
    #if UNITY_WEBPLAYER
string jsarray = "[";
foreach (string domain in domains) {
jsarray += "'"+domain+"',";
}
jsarray += "]";
Application.ExternalEval("function contains(a, obj) { " +
                      "var i = a.length; " +
                      "while (i--) { if (a[i] === obj) { return true;}} " +
                      "return false;" +
                     "} "+
                    "if(contains("+jsarray+", document.location.host)) {} else { document.location='"+redirectUrl+"'; }");
    #endif
    }
}

I hope this can help.

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.