Unity慢动作但不是玩家

时间:2016-11-08 17:44:26

标签: c# unity3d timer

我想在Unity中实现慢动作,但玩家应保持正常速度。

这是我的代码:

    float powerUpDuration = 5;           // Slow down for 5 sec
    float slowMotionTimeScale = 0.5f;    // Slow down by half
    float defaultTimeScale = 1;          // default time speed

    private void OnTriggerEnter(Collider collision)
    {
        if (collision.gameObject.tag == "Player") // Player collides with powerup
        {
            Time.timeScale = slowMotionTimeScale;   // Time get's slowed
            Time.fixedDeltaTime = Time.fixedDeltaTime * Time.timeScale;   // Smooth slow down
            InvokeRepeating("SpeedManager", 0, 1);   // Powerup Timer

            movementspeed = ... // My missing code...

        }
    }

    void SpeedManager()
    {
        if (powerUpDuration > 0)   // as long as time is left ...
        {
            powerUpDuration--;     // Countdown Timer
        }
        else      // Timer is on 0
        {
            CancelInvoke("SpeedManager");        // Stop counting
            Time.timeScale = defaultTimeScale;   // Set Time speed to default
            powerUpDuration = 5;       // reset timer

            movementspeed = ... // Reset movementspeed to default
        }
    }

唯一的问题是,我正在努力设定速度......

有人知道如何处理动作速度的时间尺度吗?

0 个答案:

没有答案