Esempio n. 1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Boundary" || other.tag == "Enemy")
        {
            return;
        }

        if (other.tag == "Shot")
        {
            var mover = other.gameObject.GetComponent <Done_Mover>();
            if (health <= gameController.GetPlayerStrength(mover.PlayerNetId))
            {
                gameController.AddScore(mover.PlayerNetId, scoreValue);
                gameController.LogDestructionEvent(tag, other.transform.position);
                health = 0;
            }
            else
            {
                health--;
            }
        }

        if (explosion != null)
        {
            var boom = Instantiate(explosion, transform.position, transform.rotation);
            NetworkServer.Spawn(boom);
        }

        if (other.tag == "Player")
        {
            var boom = Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
            NetworkServer.Spawn(boom);

            var player = other.gameObject.GetComponent <Done_PlayerController>();
            gameController.DamagePlayer(player.netId);
            health = 0;

            if (gameController.GetPlayerStrength(player.netId) <= 0)
            {
                Destroy(other.gameObject);
                gameController.CheckGameOver();
            }
        }
        else
        {
            Destroy(other.gameObject);
        }

        if (health <= 0)
        {
            Destroy(gameObject);
        }
    }