Beispiel #1
0
    public void ChangeState(BallState _newState)
    {
        if (_newState == ballInformations.state)
        {
            return;
        }
        switch (_newState)
        {
        case BallState.Grounded:
            Analytics.CustomEvent("BallGrounded", new Dictionary <string, object> {
                { "Zone", GameManager.GetCurrentZoneName() },
            });
            if (destroyTrailFX != null)
            {
                StopCoroutine(destroyTrailFX); Destroy(ballTrail);
            }
            if (ballTrail)
            {
                destroyTrailFX = StartCoroutine(DisableEmitterThenDestroyAfterDelay(ballTrail.GetComponent <ParticleSystem>(), 0.5f));
            }
            FeedbackManager.SendFeedback("event.BallGrounded", this);
            EnableGravity();
            EnableCollisions();
            rb.AddForce(ballInformations.direction.normalized * ballInformations.moveSpeed * rb.mass, ForceMode.Impulse);
            CursorManager.SetBallPointerParent(transform);
            if (ballInformations.thrower != null)
            {
                if (ballInformations.thrower.isPlayer)
                {
                    LockManager.UnlockAll();
                }
            }
            break;

        case BallState.Aimed:
            DisableGravity();
            DisableCollisions();
            break;

        case BallState.Flying:
            Highlighter.DetachBallFromPlayer();
            if (ballInformations.thrower.isPlayer)
            {
                CursorManager.SetBallPointerParent(null);
            }
            ballTrail = FeedbackManager.SendFeedback("event.BallFlying", this).GetVFX();
            Vector3 newBallScale = ballTrail.transform.localScale;
            newBallScale *= Mathf.Lerp(1f, ballInformations.ballDatas.maxFXSizeMultiplierOnPerfectReception, (GetPerfectReceptionDamageModifier() / ballInformations.ballDatas.maxDamageModifierOnPerfectReception));
            ballTrail.transform.localScale = newBallScale;
            DisableGravity();
            EnableCollisions();
            col.isTrigger = true;
            col.enabled   = true;
            ballInformations.distanceTravelled = 0;
            break;

        case BallState.Held:
            if (destroyTrailFX != null)
            {
                StopCoroutine(destroyTrailFX); Destroy(ballTrail);
            }
            if (ballTrail)
            {
                destroyTrailFX = StartCoroutine(DisableEmitterThenDestroyAfterDelay(ballTrail.GetComponent <ParticleSystem>(), 0.5f));
            }
            DisableGravity();
            DisableCollisions();
            if (ballInformations.thrower != null && ballInformations.thrower.isPlayer)
            {
                LockManager.UnlockAll();
            }
            break;
        }
        ballInformations.state = _newState;
    }