Esempio n. 1
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Player")
     {
         print("player took damage from fireball");
         player.AssessDamage();
     }
 }
Esempio n. 2
0
    void OnTriggerEnter2D(Collider2D col)
    {
        //if (col.tag == "Boss")
        // Destroy(col.gameObject);
        // If a bullet hits an enemy of the same type
        EnemyMoveScript enemy = col.gameObject.GetComponent <EnemyMoveScript>();

        if (enemy != null)
        {
            if (col.tag == "Enemy" && (enemy.type == Gun.bulletType))
            {
                Destroy(col.gameObject);
                StartCoroutine(enemyDing());
                // ... find the Enemy script and call the Hurt function.
                col.gameObject.GetComponent <Enemy>().Hurt();

                // Call the explosion instantiation.
                OnExplode();

                // Destroy the rocket.
            }
            // If a bullet hits an enemy of the wrong type
            else if (col.tag == "Enemy" && (enemy.type != Gun.bulletType))
            {
                Debug.Log("Mis-Type Collision");
                GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x * -1f, GetComponent <Rigidbody2D>().velocity.y);
            }

            // Otherwise if the player manages to shoot himself...
            else if (col.gameObject.tag == "Player")
            {
                player.AssessDamage();
                StartCoroutine(playerDing());
                // Instantiate the explosion and destroy the rocket.
                OnExplode();
            }
        }
    }