コード例 #1
0
    protected void Update()
    {
        switch (_state)
        {
        case TargetDummyState.GoingDown:
        {
            var alpha = (DateTime.UtcNow - _lastFallDownTime).TotalSeconds / FallTimeSecs;
            var euler = affectedObject.eulerAngles;

            if (alpha >= 1.0f)                             //We're down
            {
                euler.x = FallDownAngle;
                _state  = TargetDummyState.Down;
            }
            else                             //Going down
            {
                euler.x = Mathf.LerpAngle(StandUpAngle, FallDownAngle, (float)alpha);
            }

            affectedObject.eulerAngles = euler;
            break;
        }

        case TargetDummyState.Down:
            if ((DateTime.UtcNow - _lastFallDownTime).TotalSeconds > StayDownTime)
            {
                _state = TargetDummyState.GoingUp;
                _lastStandingUpTime = DateTime.UtcNow;
            }
            break;

        case TargetDummyState.GoingUp:
        {
            var alpha = (DateTime.UtcNow - _lastStandingUpTime).TotalSeconds / StandUpTime;
            var euler = affectedObject.eulerAngles;

            if (alpha >= 1.0f)                             //We're up
            {
                euler.x = StandUpAngle;
                _state  = TargetDummyState.Up;
            }
            else                             //Going up
            {
                euler.x = Mathf.LerpAngle(FallDownAngle, StandUpAngle, (float)alpha);
            }

            affectedObject.eulerAngles = euler;
            break;
        }

        default:
            break;
        }
    }
コード例 #2
0
 public void Hit()
 {
     if (_state != TargetDummyState.Up)
     {
         return;
     }
     if (HitSound != null)
     {
         _audio.clip = HitSound;
         _audio.Play();
     }
     _state            = TargetDummyState.GoingDown;
     _lastFallDownTime = DateTime.UtcNow;
 }