Exemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "head")

        {
            HeadController headObj = other.gameObject.GetComponent <HeadController> ();

            Instantiate(explosion).GetComponent <Transform> ().position =
                other.gameObject.GetComponent <Transform> ().position;


            Damage(damage);

            headObj.Reset();
            headColl = other.gameObject.GetComponent <AudioSource> ();
            headColl.Play();
        }

        if (other.gameObject.tag == "coin")
        {
            CoinController coinObj = other.gameObject.GetComponent <CoinController> ();
            coinObj.Reset();
            Player.Instance.Money = Player.Instance.Money + 10;
            coinColl = other.gameObject.GetComponent <AudioSource> ();
            coinColl.Play();
        }
    }
    //Detect collisions with other gameObjects. Log and update health/points as needed.
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "prize")
        {
            Debug.Log("Collision with " + other.gameObject.tag);
            Player.Instance.Points += 10;
            AudioSource coinSound =
                gameObject.GetComponent <AudioSource> ();
            if (coinSound != null)
            {
                coinSound.Play();
            }
        }
        else if (other.gameObject.tag == "fire")
        {
            Debug.Log("Collision with " + other.gameObject.tag);
            Player.Instance.Health -= 10;
            AudioSource fireSound =
                fire.GetComponent <AudioSource> ();
            if (fireSound != null)
            {
                fireSound.Play();
            }
        }

        CoinController sp = other.gameObject.GetComponent <CoinController> ();

        if (sp != null)
        {
            sp.Reset();
        }
    }
Exemplo n.º 3
0
    void OnTriggerEnter2D(Collider2D other)
    {
        //If player collided with coin, increase the instance point by 10
        if (other.gameObject.tag == "Coin")
        {
            Player.Instance.Points += 10;
            Debug.Log("Collision with" + other.gameObject.tag);
            CoinController coin = other.gameObject.GetComponent <CoinController>();
            if (coin != null)
            {
                GameObject st = Instantiate(star);
                st.transform.position = coin.transform.position;
                coin.Reset();
            }
        }

        //If player collided with PowerCoin, increase the instance health by 10
        if (other.gameObject.tag == "PowerCoin")
        {
            Player.Instance.Health += 10;
            Debug.Log("Collision with" + other.gameObject.tag);
            PowerCoinController powerCoin = other.gameObject.GetComponent <PowerCoinController>();
            if (powerCoin != null)
            {
                GameObject sw = Instantiate(sword);
                sw.transform.position = powerCoin.transform.position;
                powerCoin.destroy();
            }
        }

        //If player collided with shark, game over
        if (other.gameObject.tag == "Shark")
        {
            Player.Instance.Health -= 20;
            Debug.Log("Collision with" + other.gameObject.tag);
            SharkController shark = other.gameObject.GetComponent <SharkController>();
            if (shark != null)
            {
                GameObject bl = Instantiate(blood);
                bl.transform.position = shark.transform.position;
            }
        }

        //If player collided with octopus, decrease the instance health by 10
        else if (other.gameObject.tag == "Octopus")
        {
            Debug.Log("Collision with" + other.gameObject.tag);
            Player.Instance.Health -= 10;
            OctopusController octopus = other.gameObject.GetComponent <OctopusController>();
            if (octopus != null)
            {
                GameObject bl = Instantiate(blood);
                bl.transform.position = octopus.transform.position;
                octopus.Reset();
            }
        }

        //If player collided with submarine, game over
        else if (other.gameObject.tag == "Submarine")
        {
            Debug.Log("Collision with" + other.gameObject.tag);
            Player.Instance.Health -= 30;
            SubmarineController submarine = other.gameObject.GetComponent <SubmarineController>();
            if (submarine != null)
            {
                GameObject bl = Instantiate(blood);
                bl.transform.position = submarine.transform.position;
            }
        }

        //If player collided with submarine, game end
        else if (other.gameObject.tag == "Bullet")
        {
            Debug.Log("Collision with" + other.gameObject.tag);
            Player.Instance.Health = 0;
            BulletController bullet = other.gameObject.GetComponent <BulletController>();
            if (bullet != null)
            {
                GameObject bl = Instantiate(blood);
                bl.transform.position = bullet.transform.position;
                bullet.destroy();
            }
        }
    }