要素理解
- timeScale(Float,默认值为1)能够影响时间流速,置0可使时间暂停
- 查阅官网文档 Time.timeScale 中可以发现对于timeScale描述中要求暂停物体的函数中所有相关变量与帧无关,而当在realtimeSinceStartup中可以对所有受时间类影响的物体产生影响。
- 帧无关即指与实际时间无关,Unity中时间计算是由相关变量决定的,很多文章中直接使用“timeScale适用范围与时间相关的变量无效”的描述不够准确。
代码
暂停UI代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class uiController : MonoBehaviour
{
[SerializeField]Transform UIPanel;
bool isPaused = false;
// Start is called before the first frame update
void Start()
{
UIPanel.gameObject