Example #1
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
Example #2
0
    private int score = 0; //VARIÁVEL DA PONTUANÇÃO


    // Start is called before the first frame update
    void Awake()                 // AWAKE ACONTECE ANTES DO START. GARANTE QUE O GAMECONTROL TENHAM SUAS VARIÁVEIS INICIANDO ANTES DOS OUTROS OBJETOS
    {
        if (gameControl == null) //SE NÃO HOUVER NENHUM GAMECONTROL, ESTE OBJETO SE TORNA O GAMECONTROL
        {
            gameControl = this;
        }

        else if (gameControl != this) //SE JÁ HOUVER UM GAMERCONTROLLER, DESTROI ESTE OBJETO E GARANTE SÓ UM GAMECONTROL EM CENA.
        {
            Destroy(gameObject);
        }
    }