当前位置:网站首页>Unity script API - time class
Unity script API - time class
2022-07-04 15:22:00 【@Night Charm】
Time class :
1、 from Unity Interface for obtaining time information
2、 Common properties :
time: The time taken from the beginning of the game to the present
timeScale: Time scaling
deltaTime: In seconds , Represents the elapsed time of each frame
unscaledDeltaTime: Elapsed time per frame unaffected by scaling
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;
// When rendering a scene , Not subject to TimeScale influence
public void Update()
{
a = Time.time;// Game run time affected by scaling
b = Time.unscaledTime;// Game run time unaffected by scaling
c = Time.realtimeSinceStartup;// Actual game run time
// Every rendered frame perform 1 Time rotate 1 degree
//1 second rotate ? degree 1 Number of frames rotated in seconds In the same case
// Multiple frames 1 Second rotation speed is fast hope 1 Frame rotation is small
// Less slow Big
this.transform.Rotate(0, speed * Time.deltaTime,0);
// Game pause , Individual objects are not affected Time.unscaledDeltaTime: Every frame interval unaffected by scaling
this.transform.Rotate(0, speed * Time.unscaledDeltaTime, 0);
// rotate / Movement speed * Time consumed per frame , Rotation can be guaranteed / The moving speed is not affected by the machine performance , And rendering effects
count++;
du += speed * Time.deltaTime;
if (a >= 1 && timeVsCount < 1)
{
//speed:100 1 Second rendering 76 Time
//speed:200 1 Second rendering 66 Time
Debug.Log(" The game frame is rendered "+count+" Time ");
Debug.Log(" The game object rotates " + du + " degree ");
Debug.Log(Time.deltaTime);
timeVsCount++;
}
if (du >= 360 && duVsCount < 1)
{
Debug.Log(" The game object rotates for one circle , The total amount of rendering is " + count + " Time ");
Debug.Log(" The game object rotates " + du + " degree ");
Debug.Log(Time.deltaTime);
duVsCount++;
}
}
// Fix 0.02 second Do it once It has nothing to do with rendering , suffer TimeScale influence
public void FixedUpdate()
{
this.transform.Rotate(0,speed,0);
}
// Game pause
private void OnGUI()
{
if (GUILayout.Button(" Pause the game "))
{
Time.timeScale = 0;
}
if (GUILayout.Button(" Keep playing "))
{
Time.timeScale = 1;
}
}
}
边栏推荐
- Partial modification - progressive development
- numpy笔记
- Go zero micro service practical series (IX. ultimate optimization of seckill performance)
- 一篇文章学会GO语言中的变量
- Luo Gu - some interesting questions 2
- [Dalian University of technology] information sharing of postgraduate entrance examination and re examination
- Align left and right!
- When synchronized encounters this thing, there is a big hole, pay attention!
- How to build a technical team that will bring down the company?
- %s格式符
猜你喜欢
夜天之书 #53 Apache 开源社群的“石头汤”
Understand the context in go language in an article
Summer Review, we must avoid stepping on these holes!
.Net 应用考虑x64生成
MySQL learning notes - data type (numeric type)
深度学习 神经网络的优化方法
AI has surpassed Dr. CS in question making?
Redis 解决事务冲突之乐观锁和悲观锁
Ffprobe common commands
這幾年爆火的智能物聯網(AIoT),到底前景如何?
随机推荐
微博、虎牙挺进兴趣社区:同行不同路
Guitar Pro 8win10 latest guitar learning / score / creation
Summer Review, we must avoid stepping on these holes!
一篇文章学会GO语言中的变量
Partial modification - progressive development
Shell 编程基础
十六进制
Luo Gu - some interesting questions
智能客服赛道:网易七鱼、微洱科技打法迥异
宽度精度
flutter 报错 No MediaQuery widget ancestor found.
Dialogue with ye Yanxiu, senior consultant of Longzhi and atlassian certification expert: where should Chinese users go when atlassian products enter the post server era?
深入JS中几种数据类型的解构赋值细节
.Net之延迟队列
c# 实现定义一套中间SQL可以跨库执行的SQL语句
对话龙智高级咨询顾问、Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?
LeetCode 1184. Distance between bus stops -- vector clockwise and counterclockwise
JS tile data lookup leaf node
Halcon knowledge: NCC_ Model template matching
夜天之书 #53 Apache 开源社群的“石头汤”