Inheritance: MonoBehaviour
 void Start()
 {
     if(instance == null) {
         instance = this;
     } else {
         Destroy(gameObject);
     }
 }
Esempio n. 2
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
     DontDestroyOnLoad(gameObject);
 }
Esempio n. 3
0
 // Use this for initialization
 void Start()
 {
     if (canvas == null)
     {
         DontDestroyOnLoad(gameObject);
         canvas = this;
     }
     else if (canvas != this)
     {
         Destroy(gameObject);
     }
 }
Esempio n. 4
0
 // Called 0th
 // Set references
 private void Awake()
 {
     // Set up singleton
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Debug.LogError("Cannot have multiple CanvasSingletons");
         Destroy(this.gameObject);
     }
 }
 // Start is called before the first frame update
 void Awake()
 {
     if (CanvasInstance == null)
     {
         CanvasInstance = this;
         DontDestroyOnLoad(this.gameObject);
     }
     else if (CanvasInstance != this)
     {
         Destroy(gameObject);
     }
     DontDestroyOnLoad(gameObject);
 }
    public void Awake()
    {
        DontDestroyOnLoad(this);

        if (FindObjectsOfType(GetType()).Length > 1)
        {
            Destroy(gameObject);
        }
        Scene scene = SceneManager.GetActiveScene();

        currentscene = scene.buildIndex;

        exits    = new bool[4];
        exits[0] = false;
        exits[1] = false;
        exits[2] = false;
        exits[3] = false;
        if (!playerSpawn)
        {
            playerSpawn = GameObject.Find("PlayerSpawn");
        }
        if (GameObject.Find("Player") == null)
        {
            playerObj      = Instantiate(playerPrefab, playerSpawn.transform.position, playerSpawn.transform.rotation);
            playerObj.name = "Player";
        }
        player        = playerObj;
        handCamera    = player.transform.Find("Body/Hands/CameraHands").GetComponent <Camera>();
        camController = player.transform.Find("Body/Camera").GetComponent <CameraController>();



        if (GameObject.Find("Canvas") != null)
        {
            canvas  = GameObject.Find("Canvas").GetComponent <CanvasSingleton>();
            loadBar = canvas.loadBar;
        }
        else
        {
            GameObject canvasObj = Instantiate(Resources.Load("Canvas"), Vector3.zero, Quaternion.identity) as GameObject;
            canvasObj.name = Resources.Load("Canvas").name;
            canvas         = canvasObj.GetComponent <CanvasSingleton>();
            loadBar        = canvas.loadBar;
        }

        DisablePlayer();
        SetCursorLock(true);
    }