Ejemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        Debug.Log("Hit:  " + other.transform.name);

        //if other is player
        //destroy  the player
        //destroy us
        if (other.tag == "Player")
        {
            //damage player
            player player = other.transform.GetComponent <player>();
            //other.transform.GetComponent<Player>().Damage();
            if (player != null)
            {
                player.Damage();
            }
            _anim.SetTrigger("OnEnemyDeath");
            _speed = 0;
            _audioSource.Play();
            Destroy(this.gameObject, 2.3f);
        }
        //if other is laser
        //destroy the laser
        //DESTROY us

        if (other.tag == "Laser")
        {
            _audioSource.Play();
            Destroy(other.gameObject);
            //trigger anim

            if (_player != null)
            {
                _player.AddScore(10);
            }
            _anim.SetTrigger("OnEnemyDeath");
            _speed = 0;

            Destroy(GetComponent.Collider2D);
            Destroy(this.gameObject, 2.3f);
        }
    }
Ejemplo n.º 2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            Destroy(this.gameObject);
            player player = other.transform.GetComponent <player>();

            if (player != null)
            {
                player.Damage();
            }
        }

        if (other.tag == "Laser")
        {
            Destroy(this.gameObject);
            if (_player != null)
            {
                _player.AddScore();
            }
            Destroy(other.gameObject);
        }
    }