Esempio n. 1
0
    void OnTriggerEnter(Collider other)
    {
        //Create Explosion
        Instantiate(explosionPrefab, transform.position, transform.rotation);

        //Destroy other object if it has Destroy tag
        if (other.gameObject.tag == "Destroy")
        {
            Destroy(other.gameObject);

            //Figure out how many destroyable gameobjects  are left
            int amountLeft = GameObject.FindGameObjectsWithTag("Destroy").Length - 1;

            if (amountLeft > 0)
            {
                //Update UI with number of objects remaining
                UIHelper_Example.ChangeText("Destroy " + amountLeft + " more to win!");
            }
            else
            {
                //Update UI with Win Text
                UIHelper_Example.ChangeText("You win!");
                SubmarineController_Example.alive = false;
            }
        }

        Destroy(gameObject);
    }
    void OnTriggerEnter(Collider collider)
    {
        alive = false;

        //Update UI Message
        UIHelper_Example.ChangeText("You Lose!");
    }
Esempio n. 3
0
    void OnTriggerEnter(Collider thingWeHit)
    {
        if (thingWeHit.tag == "Destroyable")
        {
            Destroy(thingWeHit.gameObject);              //destory target
            GameObject[] destroyableObjects = GameObject.FindGameObjectsWithTag("Destroyable");
            if (destroyableObjects.GetLength(0) - 1 == 0)
            {
                UIHelper_Example.ChangeText("YOU WIN! WOOT!");
                //Invoke ("ReloadGame", 5f);
                //ReloadGame();
            }
            else
            {
                UIHelper_Example.ChangeText("You have " + (destroyableObjects.GetLength(0) - 1) + " to destroy");
            }
        }

        GameObject newExplosion = Instantiate(explosionPrefab) as GameObject; //creates a new instance of game object

        newExplosion.transform.position = this.transform.position;            //tells the game where to instantiate
        newExplosion.transform.rotation = this.transform.rotation;

        Destroy(this.gameObject);          //destroy the torpedo
    }
    void OnTriggerEnter(Collider other)
    {
        alive = false;
        Debug.Log("Triggered with " + other.name);

        //Update UI Message
        UIHelper_Example.ChangeText("You Lose! :(");
    }
Esempio n. 5
0
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("Torpedo hit " + other.name);

        if (other.tag == "Destroy")
        {
            Destroy(other.gameObject);


            int count = GameObject.FindGameObjectsWithTag("Destroy").Length - 1;
            Debug.Log("There are " + count + " mines left");

            //No more mines to hit, user won the game :)
            if (count == 0)
            {
                GameObject       player           = GameObject.FindGameObjectWithTag("Player");
                PlayerController playerController = player.GetComponent <PlayerController> ();
                UIHelper_Example.ChangeText("YOU WON! :)");
                playerController.alive = false;

                if (playerController.alive == false)
                {
                    // Make confetti appear wherever the player is
                    GameObject confet = GameObject.FindGameObjectWithTag("Confetti");
                    confet.SetActive(true);
                    Instantiate(confet, playerController.transform.position + (player.transform.right * 3), playerController.transform.rotation);
                }
            }
        }

        //if torpedo hit, create explosion
        if (explosionPrefab != null)
        {
            Instantiate(explosionPrefab, gameObject.transform.position, Quaternion.identity);
        }
        else
        {
            Debug.Log("You forgot to assign your explosion prefab");
        }
    }
 public void KillSub()
 {
     isAlive = false;
     UIHelper_Example.ChangeText("YOU DEAD");
 }