Example #1
0
    private void OnBecameInvisible()
    {
        // only spawn a new ball if below screen
        var halfColliderHeight = gameObject.GetComponent <BoxCollider2D>().size.y / 2;

        if (transform.position.y - halfColliderHeight < ScreenUtils.ScreenBottom && !lifespanTimer.Finished)
        {
            AudioManager.Play(AudioClipName.BallLost);

            ballLostEvent.Invoke();
            SpawnNewInstance();
        }
    }
Example #2
0
 /// <summary>
 /// Spawn new ball and destroy self when out of game
 /// </summary>
 void OnBecameInvisible()
 {
     // death timer destruction is in the listener for the death timer
     if (!deathTimer.Finished)
     {
         // only lost ball if below screen
         float halfColliderHeight =
             gameObject.GetComponent <BoxCollider2D>().size.y / 2;
         if (transform.position.y - halfColliderHeight < ScreenUtils.ScreenBottom)
         {
             AudioManager.Play(AudioClipName.BallLost);
             ballLost.Invoke();
         }
         Destroy(gameObject);
     }
 }