Player.Die C# (CSharp) Метод

Die() приватный Метод

private Die ( string _sourceID ) : void
_sourceID string
Результат void
    private void Die(string _sourceID)
    {
        isDead = true;

        Player sourcePlayer = GameManager.GetPlayer(_sourceID);
        if (sourcePlayer != null)
        {
            sourcePlayer.kills++;
            GameManager.instance.onPlayerKilledCallback.Invoke(username, sourcePlayer.username);
        }

        deaths++;

        //Disable components
        for (int i = 0; i < disableOnDeath.Length; i++)
        {
            disableOnDeath[i].enabled = false;
        }

        //Disable GameObjects
        for (int i = 0; i < disableGameObjectsOnDeath.Length; i++)
        {
            disableGameObjectsOnDeath[i].SetActive(false);
        }

        //Disable the collider
        Collider _col = GetComponent<Collider>();
        if (_col != null)
            _col.enabled = false;

        //Spawn a death effect
        GameObject _gfxIns = (GameObject)Instantiate(deathEffect, transform.position, Quaternion.identity);
        Destroy(_gfxIns, 3f);

        //Switch cameras
        if (isLocalPlayer)
        {
            GameManager.instance.SetSceneCameraActive(true);
            GetComponent<PlayerSetup>().playerUIInstance.SetActive(false);
        }

        Debug.Log(transform.name + " is DEAD!");

        StartCoroutine(Respawn());
    }

Usage Example

Пример #1
0
        protected virtual void OnCollide(Player player)
        {
            switch (Direction)
            {
            case Directions.Up:
                if (player.Speed.Y >= 0f && player.Bottom <= base.Bottom)
                {
                    player.Die(new Vector2(0f, -1f));
                }
                break;

            case Directions.Down:
                if (player.Speed.Y <= 0f)
                {
                    player.Die(new Vector2(0f, 1f));
                }
                break;

            case Directions.Left:
                if (player.Speed.X >= 0f)
                {
                    player.Die(new Vector2(-1f, 0f));
                }
                break;

            case Directions.Right:
                if (player.Speed.X <= 0f)
                {
                    player.Die(new Vector2(1f, 0f));
                }
                break;
            }
        }
All Usage Examples Of Player::Die