当前位置:网站首页>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;
}
}
}
边栏推荐
猜你喜欢

这几年爆火的智能物联网(AIoT),到底前景如何?
![[differential privacy and data adaptability] differential privacy code implementation series (XIV)](/img/de/c053f376fe90c2697ffc640fab57e8.jpg)
[differential privacy and data adaptability] differential privacy code implementation series (XIV)

Weibo and Huya advance into interest communities: different paths for peers

科普达人丨一文看懂阿里云的秘密武器“神龙架构”

在芯片高度集成的今天,绝大多数都是CMOS器件

Redis 发布和订阅

flutter 报错 No MediaQuery widget ancestor found.

产品好不好,谁说了算?Sonar提出分析的性能指标,帮助您轻松判断产品性能及表现

What is the future of the booming intelligent Internet of things (aiot) in recent years?

Lombok使用引发的血案
随机推荐
华为云数据库DDS产品深度赋能
MySQL learning notes - data type (numeric type)
Force button brush question 01 (reverse linked list + sliding window +lru cache mechanism)
直播预告 | PostgreSQL 内核解读系列第二讲:PostgreSQL 体系结构
Techsmith Camtasia Studio 2022.0.2屏幕录制软件
UFO: Microsoft scholars have proposed a unified transformer for visual language representation learning to achieve SOTA performance on multiple multimodal tasks
大神详解开源 BUFF 增益攻略丨直播
Shell 编程基础
How to rapidly deploy application software under SaaS
中国主要城市人均存款出炉,你达标了吗?
Unity脚本API—GameObject游戏对象、Object 对象
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
压力、焦虑还是抑郁? 正确诊断再治疗
.Net 应用考虑x64生成
Luo Gu - some interesting questions 2
Redis 解决事务冲突之乐观锁和悲观锁
开源人张亮的 17 年成长路线,热爱才能坚持
Understand the context in go language in an article
Detailed explanation of MySQL composite index (multi column index) use and optimization cases
这几年爆火的智能物联网(AIoT),到底前景如何?