Ejemplo n.º 1
0
        void Update()
        {
            // We don't want OnLookUpdate to be called on each frame. This is to prevent the gazing from acting faster on faster CPU's.
            // Rather, OnLookUpdate is called every _threshold seconds while the elf is under gaze by santa.
            _lastTimeStep += Time.deltaTime;
            if (_lastTimeStep + Time.deltaTime > _threshold)
            {
                _lastTimeStep = _lastTimeStep % _threshold;
                if (_isUnderGaze)
                {
                    OnLookUpdate();
                }
                else
                {
                    if (!_isTurnedToBlack)
                    {
                        _armAnimation.speed = Mathf.Max(_armAnimation.speed * 0.95f, MinWorkingSpeed);
                    }
                    else
                    {
                        _armAnimation.speed = _armAnimation.speed * 0.95f;
                    }
                }
            }
            if (Time.time - _underGazeTime > _acknowledgeSoundThreshold && s_canAcknowledge)
            {
                s_canAcknowledge = false;
                SoundManager.GetSharedManager().PlayAcknowledgeSound(transform.position);
            }
            if (Time.time - _underGazeTime > _pushedSoundTreshold && s_canBePushed)
            {
                s_canBePushed       = false;
                s_pushedAudioSource = SoundManager.GetSharedManager().PlayPushedSound(transform.position);
            }

            _focusMarker.transform.Rotate(Vector3.up * Time.deltaTime * _armAnimation.speed * 150);

            if (numHammerHits >= 10)
            {
                SpawnGift();
            }
            _shouldBurnToBlack = _isUnderJesusGaze && (Time.time - _jesusGazeStartTime > _jesusTolerance);
            if (_shouldBurnToBlack && !_isTurnedToBlack)
            {
                BurnToBlack();
            }

            if (!_isTurnedToBlack)
            {
                // Elves will look at Jesus if the head rotation is within normal "human" limits.
                Quaternion angleToTarget = Quaternion.LookRotation(JesusLookTarget.transform.position);
                float      angleDiff     = Quaternion.Angle(angleToTarget, originalDirection);
                if (!lookAtSanta)
                {
                    if (angleDiff < 90)
                    {
                        HeadJoint.transform.LookAt(JesusLookTarget.transform);
                    }
                    else
                    {
                        HeadJoint.transform.rotation = originalDirection;
                    }
                }
            }

            if (_pointOfNoReturn)
            {
                _jesusDelegate.OnElfDestroyed(transform);
                _bloodAndGoreFactory.CreateBloodAndGore(transform.position);
                GameData.GetCurrentGameData().DecrementRemainingElfCount();
                Destroy(s_pushedAudioSource);
                Destroy(gameObject);
            }
        }