void OnTriggerEnter(Collider col) { if (col == leftGoal || col == rightGoal) { if (OnPlayerScore != null) // if there are listeners to this event { var eventArgs = new BallScoreEventArgs(col); OnPlayerScore(null, eventArgs); } } }
// Called when someone scores private void HandlePlayerScore(object sender, BallScoreEventArgs eventArgs) { if (eventArgs.Collider == leftGoal) { rightPlayerScore++; } else { leftPlayerScore++; } UpdateScores(); ball.RestartBall(); }