当前位置:网站首页>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;
}
}
}
边栏推荐
- [Dalian University of technology] information sharing of postgraduate entrance examination and re examination
- 华为云数据库DDS产品深度赋能
- Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
- %f格式符
- go-zero微服务实战系列(九、极致优化秒杀性能)
- 2022 financial products that can be invested
- Memory management summary
- 宽度与对齐
- 基于MAX31865的温度控制系统
- UFO: Microsoft scholars have proposed a unified transformer for visual language representation learning to achieve SOTA performance on multiple multimodal tasks
猜你喜欢
随机推荐
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Ffmpeg Visual Studio development (IV): audio decoding
关于FPGA底层资源的细节问题
华为云数据库DDS产品深度赋能
%s格式符
Ffprobe common commands
selenium 浏览器(2)
Deep learning network regularization
Luo Gu - some interesting questions
力扣刷题01(反转链表+滑动窗口+LRU缓存机制)
Introduction to asynchronous task capability of function calculation - task trigger de duplication
函数计算异步任务能力介绍 - 任务触发去重
TechSmith Camtasia studio 2022.0.2 screen recording software
Luo Gu - some interesting questions 2
Is BigDecimal safe to calculate the amount? Look at these five pits~~
Unity update process_ Principle of unity synergy
How to handle exceptions in multithreading?
左右对齐!
LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路
Preliminary exploration of flask: WSGI









