当前位置:网站首页>Unity脚本API—Time类
Unity脚本API—Time类
2022-07-04 14:13:00 【@夜魅】
Time类:
1、从Unity获取时间信息的接口
2、常用属性:
time:从游戏开始到现在所用时间
timeScale:时间缩放
deltaTime:以秒为单位,表示每帧的经过时间
unscaledDeltaTime:不受缩放影响的每帧经过时间
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
///
/// </summary>
public class TimeDemo : MonoBehaviour
{
public int speed = 100;
public float a,b,c;
public int count;
public float du;
public int timeVsCount;
public int duVsCount;
//渲染场景时执行,不受TimeScale影响
public void Update()
{
a = Time.time;//受缩放影响的游戏运行时间
b = Time.unscaledTime;//不受缩放影响的游戏运行时间
c = Time.realtimeSinceStartup;//实际游戏运行时间
//每渲染帧 执行1次 旋转1度
//1秒 旋转?度 1秒内旋转帧数 相同的情况下
//帧多 1秒旋转速度快 希望1帧旋转量小
// 少 慢 大
this.transform.Rotate(0, speed * Time.deltaTime,0);
//游戏暂停,个别物体不受影响 Time.unscaledDeltaTime:不受缩放影响的每帧间隔
this.transform.Rotate(0, speed * Time.unscaledDeltaTime, 0);
//旋转/移动速度 * 每帧消耗时间,可以保证旋转/移动速度不受机器性能,以及渲染影响
count++;
du += speed * Time.deltaTime;
if (a >= 1 && timeVsCount < 1)
{
//speed:100 1秒渲染76次
//speed:200 1秒渲染66次
Debug.Log("游戏帧渲染了"+count+"次");
Debug.Log("游戏对象旋转了" + du + "度");
Debug.Log(Time.deltaTime);
timeVsCount++;
}
if (du >= 360 && duVsCount < 1)
{
Debug.Log("游戏对象旋转一周,共计渲染量为" + count + "次");
Debug.Log("游戏对象旋转了" + du + "度");
Debug.Log(Time.deltaTime);
duVsCount++;
}
}
//固定 0.02 秒 执行一次 与渲染无关,受TimeScale影响
public void FixedUpdate()
{
this.transform.Rotate(0,speed,0);
}
//游戏暂停
private void OnGUI()
{
if (GUILayout.Button("暂停游戏"))
{
Time.timeScale = 0;
}
if (GUILayout.Button("继续游戏"))
{
Time.timeScale = 1;
}
}
}
边栏推荐
- PLC Analog input analog conversion FC s_ ITR (CoDeSys platform)
- 内存管理总结
- Quick introduction to automatic control principle + understanding
- 局部修改-渐进型开发
- MySQL学习笔记——数据类型(2)
- UFO:微软学者提出视觉语言表征学习的统一Transformer,在多个多模态任务上达到SOTA性能!...
- Luo Gu - some interesting questions 2
- Width accuracy
- [differential privacy and data adaptability] differential privacy code implementation series (XIV)
- Usage of database functions "recommended collection"
猜你喜欢

Redis publier et s'abonner

IO流:节点流和处理流详细归纳。

TechSmith Camtasia studio 2022.0.2 screen recording software

从0到1建设智能灰度数据体系:以vivo游戏中心为例

Preliminary exploration of flask: WSGI

Halcon knowledge: NCC_ Model template matching

03-存储系统

Summer Review, we must avoid stepping on these holes!

Flutter reports an error no mediaquery widget ancestor found

03 storage system
随机推荐
Intelligent customer service track: Netease Qiyu and Weier technology play different ways
【学习笔记】拟阵
深度学习 神经网络的优化方法
Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
MySQL学习笔记——数据类型(2)
.Net 应用考虑x64生成
Leecode learning notes - Joseph problem
开源人张亮的 17 年成长路线,热爱才能坚持
%s格式符
%S format character
Introduction to asynchronous task capability of function calculation - task trigger de duplication
Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
Five minutes of machine learning every day: how to use matrix to represent the sample data of multiple characteristic variables?
Leetcode 1200 minimum absolute difference [sort] the way of leetcode in heroding
找数字
Halo effect - who says that those with light on their heads are heroes
大神详解开源 BUFF 增益攻略丨直播
selenium 元素交互
深度学习 神经网络案例(手写数字识别)