In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to achieve millisecond delay callback function in Unity". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to achieve millisecond delay callback function in Unity".
API
1: Time.deltaTime
In fact, it is the time of execution per frame.
Function realization
Simply talk about the implementation of the function, the source code will be posted directly below.
Each new task (callback) records the time the task was created and the delay, as well as its own event callback. Determine whether the time of the current frame is greater than that created by each frame (time of task + time of delay)
Code using System;using System.Collections;using System.Collections.Generic;using UnityEngine;public class TickManager: MonoBehaviour {/ / Start is called before the first frame update public int NOW; private List _ ticks = new List () Private void Update () {/ / Test-manually create a callback if (Input.GetKeyDown (KeyCode.A)) after 5 seconds {Tick tick = new Tick (()) = > {Debug.Log ("Task execution");}, 5000Now); _ ticks.Add (tick) } / / the millisecond time used in each frame uint deltaTime = (uint) (Time.deltaTime * 1000); / / traverses to determine whether the tasks in the collection execute for (int I = 0; I
< deltaTime; i++) { Debug.Log("帧数 " + NOW); for (int j = 0; j < _ticks.Count; j++) { _ticks[j].OnTick(NOW); } ++NOW; } } class Tick { //创建任务的时间 public int currentTime { get; set; } //需要延迟的时间 public int delayTime { get; set; } //延迟后的回调事件 public Action action { get; set; } //构造函数--初始化 public Tick(Action ac, int del, int now) { action = ac; delayTime = del; currentTime = now; } //判断该任务是否执行 public void OnTick(int now) { if (now >= (currentTime + delayTime) {action ();} else {Debug.Log ("time not yet" + now);} above is all the content of the article "how to achieve millisecond delay callback in Unity". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.