Ejemplo n.º 1
0
    //method when Nemesis collides with player or laser
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            if (_player != null)
            {
                Instantiate(_explosion, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
                _player.PlayerDamage();
            }

            Destroy(this.gameObject);
        }
        else if (collision.tag == "Laser")
        {
            Destroy(collision.gameObject);
            if (_player != null)
            {
                Instantiate(_explosion, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);

                //add 10 to the player's score
                _player.AddToPlayerScore();
            }

            Destroy(this.gameObject);
        }
    }
Ejemplo n.º 2
0
    //method for when enemy makes contact with the player or laser
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            if (_player != null)
            {
                Instantiate(_explosion, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
                _player.PlayerDamage(); //calls the playerdamage() from the playerleveltwo script to subtract 1 life from the player
            }

            Destroy(this.gameObject);
        }
        else if (collision.tag == "Laser")
        {
            Destroy(collision.gameObject);
            Instantiate(_explosion, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
            //add 10 to score
            _player.AddToPlayerScore();

            Destroy(this.gameObject);
        }
    }