当前位置:网站首页>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;
}
}
}
边栏推荐
- 干货 | fMRI标准报告指南新鲜出炉啦,快来涨知识吧
- 基于MAX31865的温度控制系统
- 【读书会第十三期】视频文件的编码格式
- 浮点数如何与0进行比较?
- [Dalian University of technology] information sharing of postgraduate entrance examination and re examination
- Solve the error of JSON module in PHP compilation and installation under CentOS 6.3
- . Net applications consider x64 generation
- 一篇文章学会GO语言中的变量
- Introduction of text mining tools [easy to understand]
- LeetCode 35. Search the insertion position - vector traversal (O (logn) and O (n) - binary search)
猜你喜欢
AI has surpassed Dr. CS in question making?
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
中国主要城市人均存款出炉,你达标了吗?
這幾年爆火的智能物聯網(AIoT),到底前景如何?
03 storage system
Redis publier et s'abonner
近一亿美元失窃,Horizon跨链桥被攻击事件分析
flutter 报错 No MediaQuery widget ancestor found.
[Dalian University of technology] information sharing of postgraduate entrance examination and re examination
Guitar Pro 8win10 latest guitar learning / score / creation
随机推荐
js平铺数据查找叶子节点
The per capita savings of major cities in China have been released. Have you reached the standard?
这几年爆火的智能物联网(AIoT),到底前景如何?
压力、焦虑还是抑郁? 正确诊断再治疗
An article learns variables in go language
暑期复习,一定要避免踩这些坑!
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
浮点数如何与0进行比较?
输入宽度!
Unity脚本生命周期 Day02
文本挖掘工具的介绍[通俗易懂]
JS tile data lookup leaf node
Temperature control system based on max31865
数据库函数的用法「建议收藏」
UFO: Microsoft scholars have proposed a unified transformer for visual language representation learning to achieve SOTA performance on multiple multimodal tasks
They are all talking about Devops. Do you really understand it?
MySQL组合索引(多列索引)使用与优化案例详解
Ffprobe common commands
科研漫画 | 联系到被试后还需要做什么?
LeetCode 35. Search the insertion position - vector traversal (O (logn) and O (n) - binary search)