Example #1
0
 void OnDestroy()
 {
     if (_i == this)
     {
         _i = null;
     }
 }
Example #2
0
 void Awake()
 {
     if (_i)
     {
         Destroy(gameObject);
     }
     else
     {
         _i = this;
     }
 }
Example #3
0
    public static void OnPlayerDie(Player.DeathType type)
    {
        if (_i._firstRoundabout)
        {
            _i.StartCoroutine(_Respawn());
        }
        else if (_i._lives == 0)
        {
            _i._dead = true;
        }
        else
        {
            --_i._lives;
            _i.StartCoroutine(_Respawn());
        }

        if (_i._dead)
        {
            _i._onDie.Invoke();
            if (!Roundabout.Active.OffsetCamera)
            {
                var camEnd = Camera.main.transform.position + Vector3.right * 10;
                _i.StartCoroutine(MoveCamera(_i._camDeathTime, camEnd, () => {
                    DeathsUi.OnDeath(type, true);
                }));
            }
            else
            {
                DeathsUi.OnDeath(type, true);
            }
        }
        else
        {
            _i._onCrash.Invoke();
            DeathsUi.OnDeath(type, false);
        }

        IEnumerator _Respawn()
        {
            yield return(new WaitForSeconds(_i._respawnTime));

            Destroy(Player.Instance.gameObject);
            yield return(null);

            var player = Instantiate <Player>(_i._playerPrefab);

            player.transform.position = Polar.FromPolar(0, Roundabout.Active.RadiusInner, Roundabout.Active.transform.position);
            player.transform.forward  = Polar.PolarForward(0, Roundabout.Active.RadiusInner);
        }
    }