Exemplo n.º 1
0
    /// <summary>
    /// Destroys ball when it becomes invisible
    /// </summary>
    void OnBecameInvisible()
    {
        // death timer destruction is in Update
        if (!deathTimer.Finished)
        {
            // only lost ball if outside screen
            if (OutsideScreen())
            {
                // invoke ball lost event
                if (transform.position.x > 0)
                {
                    AudioManager.Play(AudioClipName.ScorePoint);
                    ballLostEvent.Invoke(ScreenSide.Left, points);
                }
                else
                {
                    AudioManager.Play(AudioClipName.ScorePoint);
                    ballLostEvent.Invoke(ScreenSide.Right, points);
                }

                // destroy self
                Destroy(gameObject);
            }
        }
    }
Exemplo n.º 2
0
 private void OnBecameInvisible()
 {
     if (Camera.main != null && gameObject != null && !timer.Finished && gameObject.transform.position.y <= ScreenUtils.ScreenBottom)
     {
         ballLostEvent.Invoke();
         Destroy(gameObject);
     }
 }
Exemplo n.º 3
0
 // Destroy the ball when it left the screen
 void OnBecameInvisible()
 {
     // Make sure the ball is outside of the screen before redraw it
     if (!deathTimer.Finished && !InsideScreen())
     {
         if (gameObject.transform.position.x < 0)
         {
             // Add score to the right player
             scoreEvent.Invoke(ScreenSide.Right, points);
             // BallSpawner.DrawBall()
             ballLostEvent.Invoke();
         }
         // If the ball goes out on the right side of the screen
         else
         {
             // Add score to the left player
             scoreEvent.Invoke(ScreenSide.Left, points);
             ballLostEvent.Invoke();
         }
         AudioManager.Play(AudioClipName.BallLost);
         Destroy(gameObject);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Destroys ball when offscreen
 /// </summary>
 private void OnBecameInvisible()
 {
     // Regulates scoring
     if (transform.position.x + ballHalfWidth < ScreenUtils.ScreenLeft ||
         transform.position.x + ballHalfWidth > ScreenUtils.ScreenRight)
     {
         // Checks for screen side to apply appropriate scoring
         // Ball goes off Right --- Scores + for Left
         if (transform.position.x > 0)
         {
             pointsAddedEvent.Invoke(ScreenSide.Left, score);
             ballLostEvent.Invoke();
             deathTimer.Stop();
         }
         // Ball goes off Left --- Score + for Right
         else if (transform.position.x < 0)
         {
             pointsAddedEvent.Invoke(ScreenSide.Right, score);
             ballLostEvent.Invoke();
             deathTimer.Stop();
         }
         Destroy(gameObject);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 ///     Adds points to the side that scored based on
 ///      which side the ball was on.
 ///      (Called from DestroyBallWhenInvisible)
 /// </summary>
 public void AddPoints()
 {
     addPoints.Invoke(transform.position.x > 0.0f
         ? ScreenSide.Left : ScreenSide.Right,
                      ( int )points);
 }