private void OnCollisionEnter(Collision collision)
        {
            _currentlyHitBall = collision.gameObject.GetComponent <BallController>();

            if (_currentlyHitBall)
            {
                // The interpolation here with 100f as max sqrMagnitude is purely empirical.
                // In most sensible scenarios sqrMagnitude will be between 10 and 500, and in some extreme speeds will be a lot more (around 2000).
                // I clamp these cases as 500 max as well here. Note that this interpolates for the impact velocity only. The game auido setting is globally
                // applied in the AuidioManager.
                eventService.TriggerEvent(Constants.AUDIO_BALL_HIT_BALL, Mathf.Clamp01(ballRB.velocity.sqrMagnitude / 500f));
            }

            else // if not a ball, we must be hitting a wall
            {
                eventService.TriggerEvent(Constants.AUDIO_BALL_HIT_WALL, Mathf.Clamp01(ballRB.velocity.sqrMagnitude / 500f));
            }
        }
Exemplo n.º 2
0
        private void OnCollisionEnter(Collision collision)
        {
            _currentlyHitBall = collision.gameObject.GetComponent <BallController>();

            if (_currentlyHitBall)
            {
                // The interpolation here with 100f as max sqrMagnitude is purely empirical.
                // In most sensible scenarios sqrMagnitude will be between 10 and 500, and in some extreme speeds will be a lot more (around 2000).
                // I clamp these cases as 500 max as well here. Note that this interpolates for the impact velocity only. The game auido setting is globally
                // applied in the AuidioManager.
                eventService.TriggerEvent(Constants.AUDIO_BALL_HIT_BALL, Mathf.Clamp01(ballRB.velocity.sqrMagnitude / 500f));
                //Debug.Log($"Triggering BallHitBall with sqrMagnitude: {_cueBallRB.velocity.sqrMagnitude}, resulting in: {_cueBallRB.velocity.sqrMagnitude / 500f}");

                if (!_hitBallsDuringShot.Contains(_currentlyHitBall))
                {
                    Debug.Log($"UNIQUE HIT: {_currentlyHitBall.name}");
                    _hitBallsDuringShot.Add(_currentlyHitBall);

                    if (_hitBallsDuringShot.Count == Constants.GAMEPLAY_TOTAL_TARGET_BALL_COUNT)
                    {
                        _gameSessionService.SetScore(_gameSessionService.GetScore() + 1);
                        eventService.TriggerEvent(Constants.SESSION_DATA_SCORE_UPDATED);
                        Debug.Log("SCORE!");
                        if (_gameSessionService.GetScore() == Constants.GAMEPLAY_TOTAL_SCORES_TO_WIN)
                        {
                            eventService.TriggerEvent(Constants.GAME_OVER);
                            Debug.Log("GAME OVER!");
                        }
                    }
                }
            }
            else // if not a ball, we must be hitting a wall
            {
                eventService.TriggerEvent(Constants.AUDIO_BALL_HIT_WALL, Mathf.Clamp01(ballRB.velocity.sqrMagnitude / 500f));
                //Debug.Log($"Triggering BallHitWall with sqrMagnitude: {_cueBallRB.velocity.sqrMagnitude}, resulting in: {_cueBallRB.velocity.sqrMagnitude / 500f}");
            }
        }