簡體   English   中英

如何使用字符控制器操縱Time.timeScale?

[英]How do I manipulate Time.timeScale with the character controller?

我正在嘗試做類似原型游戲SuperHot的事情,其中​​“時間只有在移動時移動”。

我能想到的方法包括使用輸入或字符控制器的速度來操縱Time.timeScale。

以下是我的操作方法:

using UnityEngine;
using System.Collections;

public class TimeMechanic : MonoBehaviour {
private float targetScale;

// Use this for initialization
void Start ()
{
    targetScale = 0.02f;
}

// Update is called once per frame
void Update ()
{
    Time.timeScale = targetScale; //setting the timeScale
    if (Input.GetAxis ("Horizontal") != 0 || Input.GetAxis ("Vertical") != 0)
    {
        targetScale += 0.03f; //incrementing the variable by 0.03
        if (targetScale > 1f)
        {
            targetScale = 1f; //limits the variable to 1 at max
        }
    }
    else
    {
        targetScale -= 0.03f; //decrementing the variable by 0.03
        if (targetScale < 0.02f)
        {
            targetScale = 0.02f; //limits variable to 0.02 at min
        }
    }
    Debug.Log (targetScale);
}

}

我的問題:

  1. 用角色控制器的速度操縱timeScale是否可行?
  2. 我需要在此代碼中進行改進嗎?

這將取決於您的算法。 實際上,當您減少timeScale ,它將具有循環依賴性。 取決於Input會更好,但這取決於您期望的外觀。

當timeScale設置為零時,如果您所有功能均與幀速率無關,則游戲基本上會暫停。

除了realtimeSinceStartup之外,timeScale影響Time類的所有時間和增量時間測量變量。

如果降低timeScale,建議也將Time.fixedDeltaTime降低相同的量。

當timeScale設置為零時,將不會調用FixedUpdate函數。

由於Physics是最有優先FixedUpdate既要注意以上幾點,除非你的游戲有很多違規行為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM