コード例 #1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        // Skip the call if the gameObjects are the same or if the gameObject isn't a Player
        if (other.gameObject == this.gameObject)
        {
            return;
        }
        if (other.tag != "Player")
        {
            return;
        }



        // Skip the call if we or the other player isn't alive
        if (!Lives.IsAlive || !Lives.HasLives)
        {
            return;
        }
        PlayerController collidedPlayer = other.gameObject.GetComponent <PlayerController>();

        if (!collidedPlayer.Lives.IsAlive || !collidedPlayer.Lives.HasLives)
        {
            return;
        }

        Debug.Log("Player " + collidedPlayer.Info.ID + " Made an Attack");

        // Flag that they are dead and modify Health State
        collidedPlayer.Lives.IsAlive = false;
        collidedPlayer.Lives.DecreaseLife(1);
        Lives.IncreaseLife(1);

        // Disable all the players scripts but this one
        //var colliderPlayerScripts = new List<MonoBehaviour>();
        //colliderPlayerScripts.AddRange(collidedPlayer.gameObject.GetComponents<MonoBehaviour>());
        //colliderPlayerScripts.AddRange(collidedPlayer.gameObject.GetComponentsInChildren<MonoBehaviour>());
        //foreach (var script in colliderPlayerScripts)
        //{
        //    if (script is PlayerController) return;
        //    script.enabled = false;
        //}
        //var children = collidedPlayer.GetComponentsInChildren<Transform>();
        //foreach (var child in children)
        //{
        //    child.gameObject.SetActive(false);
        //}

        // Enable and run the timer
        collidedPlayer.RespawnTimer.enabled = true;
        collidedPlayer.RespawnTimer.StartClockTimer();
    }