コード例 #1
0
        // Update is called once per frame
        private void Update()
        {
            if (_previousPlayerDirection != PlayerDirection.CurrentDirection)
            {
                Debug.Log("Player change direction, Re-initialize state.");
                Initialize();
            }

            // set Crosshair transform base on angle.
            var angle = Mathf.Lerp(_currentRotationAngle.From, _currentRotationAngle.To, _anglePercentage);

            Debug.Log($"Current angle {angle}");
            transform.position = PositionFromAngle(angle) + PlayerPosition.position;

            _anglePercentage += Speed * Time.unscaledDeltaTime;
            Debug.Log($"angle percentage {_anglePercentage}");

            if (_anglePercentage < 1f)
            {
                return;
            }

            _currentRotationAngle = FlipRotationAngle(_currentRotationAngle);
            _anglePercentage      = 0f;
        }
コード例 #2
0
 private static RotationAngle FlipRotationAngle(RotationAngle rotationAngle)
 {
     return(new RotationAngle
     {
         From = rotationAngle.To,
         To = rotationAngle.From
     });
 }
コード例 #3
0
 private void Initialize()
 {
     _currentRotationAngle    = RotationAngleFromDirection(PlayerDirection.CurrentDirection);
     _previousPlayerDirection = PlayerDirection.CurrentDirection;
     _anglePercentage         = 0f;
 }