示例#1
0
    void Die()
    {
        if (myInfo.Explosion != null)
        {
            Instantiate(myInfo.Explosion, transform.position, transform.rotation);
        }

        //If this unit is not the player: Remove it from the unitTracker and raise the OnUnitDeath event.
        if (!myInfo.IsPlayerShip)
        {
            UnitTracker.RemoveUnit(gameObject);
            try
            {
                if (OnUnitDeath != null)
                {
                    OnUnitDeath();
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.Message + "\n" + ex.StackTrace);
            }
        }
        else //If this unit is the player: Remove its reference in the unitTracker and raise the OnPlayerDeath event.
        {
            UnitTracker.PlayerShip = null;
            try {
                if (OnPlayerDeath != null)
                {
                    OnPlayerDeath();
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.Message + "\n" + ex.StackTrace);
            }
        }

        if (myInfo.IsPooled)
        {
            gameObject.SetActive(false);
        }
        else
        {
            Destroy(gameObject);
        }
    }
 void OnDisable()
 {
     UnitTracker.RemoveUnit(gameObject);
 }