Esempio n. 1
0
 /// <summary>
 /// Starts a camera shake using the provided profile
 /// </summary>
 /// <param name="profile">profile to use</param>
 public void StartShake(CameraShakeProfile profile)
 {
     if (!_isShaking)
     {
         StartCoroutine(Shake(profile));
     }
 }
Esempio n. 2
0
        private IEnumerator Shake(CameraShakeProfile profile)
        {
            _isShaking = true;
            var       seed            = Random.Range(-256, 256);
            TimeSince start           = 0f;
            var       initialPosition = transform.localPosition;
            var       initialRotation = transform.localEulerAngles;

            while (start <= profile.Duration)
            {
                var positionOffset = profile.Resolve(seed, start);
                positionOffset.Scale(profile.PositionScalar);
                transform.localPosition = initialPosition + positionOffset;

                var rotationOffset = profile.Resolve(seed, start);
                rotationOffset.Scale(profile.RotationScalar);
                transform.localEulerAngles = initialRotation + rotationOffset;
                yield return(null);
            }
            transform.localPosition    = initialPosition;
            transform.localEulerAngles = initialRotation;
            _isShaking = false;
        }