Ejemplo n.º 1
0
    // the ammo doesn't know at what it is being shot, only works with rigidbody2d
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!getDestroyed)
        {
            //Debug.Log("Hit Something : " + collision.name);
            if (collision.CompareTag("Player") && gameObject.CompareTag("enemyAmmo"))
            {
                getDestroyed = true;
                RocketController tempRC = collision.GetComponentInParent <RocketController>();
                if (tempRC != null)
                {
                    //Debug.Log("Hit Player");
                    gameObject.GetComponent <CapsuleCollider2D>().enabled = false;
                    tempRC.TakeDamagePlayer(damageOutput);
                    Destroy(gameObject);
                    //return;     // no need       // early return so as to not check further if statement
                }
            }

            else if (collision.CompareTag("Enemy") && !gameObject.CompareTag("enemyAmmo"))
            {
                getDestroyed = true;
                var tempUC = collision.GetComponentInParent <UFOController>();
                if (tempUC != null)
                {
                    //Debug.Log("Hit Enemy" + collision.tag);
                    gameObject.GetComponent <CapsuleCollider2D>().enabled = false;
                    tempUC.TakeDamageEnemy(damageOutput);
                    Destroy(gameObject);
                }
            }

            else if (collision.CompareTag("UfoBoss") && !gameObject.CompareTag("enemyAmmo"))
            {
                getDestroyed = true;
                BossScript tempUC = collision.GetComponentInParent <BossScript>();
                if (tempUC != null)
                {
                    //Debug.Log("Hit Enemy" + collision.tag);
                    gameObject.GetComponent <CapsuleCollider2D>().enabled = false;
                    tempUC.TakeDamageEnemy(damageOutput);
                    Destroy(gameObject);
                }
            }
            //Destroy(gameObject);
        }
    }