当前位置:网站首页>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;
}
}
}
边栏推荐
- MYSQL索引优化
- 进制形式
- UFO: Microsoft scholars have proposed a unified transformer for visual language representation learning to achieve SOTA performance on multiple multimodal tasks
- 怎么判断外盘期货平台正规,资金安全?
- Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
- c# 实现定义一套中间SQL可以跨库执行的SQL语句
- 暑期复习,一定要避免踩这些坑!
- Unity脚本介绍 Day01
- Unity脚本API—Time类
- How to rapidly deploy application software under SaaS
猜你喜欢
TechSmith Camtasia studio 2022.0.2 screen recording software
Flutter reports an error no mediaquery widget ancestor found
产品好不好,谁说了算?Sonar提出分析的性能指标,帮助您轻松判断产品性能及表现
Summer Review, we must avoid stepping on these holes!
从0到1建设智能灰度数据体系:以vivo游戏中心为例
夜天之书 #53 Apache 开源社群的“石头汤”
Weekly recruitment | senior DBA annual salary 49+, the more opportunities, the closer success!
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
Unity脚本生命周期 Day02
Data Lake Governance: advantages, challenges and entry
随机推荐
%f格式符
微博、虎牙挺进兴趣社区:同行不同路
Deep learning neural network case (handwritten digit recognition)
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?
Lombok使用引发的血案
左右对齐!
LeetCode 1184. 公交站间的距离 ---vector顺逆时针
Deep learning network regularization
%S format character
Weekly recruitment | senior DBA annual salary 49+, the more opportunities, the closer success!
深度学习 神经网络的优化方法
js平铺数据查找叶子节点
音视频技术开发周刊 | 252
An article learns variables in go language
一篇文章学会GO语言中的变量
Implementation of web chat room
How did the beyond concert 31 years ago get super clean and repaired?
Unity预制件Prefab Day04
LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04
基于MAX31865的温度控制系统