Unity定时器

本文介绍了Unity引擎中如何创建一个不受TimeScale影响的定时器,详细讨论了TimeScale对游戏逻辑的影响,并提供了一种实用的C#实现定时器的方法,确保游戏关键任务的定时执行不受玩家调整游戏速度的影响。
摘要由CSDN通过智能技术生成

1.Unity定时器受TimeScale影响

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;



public enum ETimerType
{
    OneShot,
    Repeated,
}


public class Timer
{

    //当前这个定时器对象的唯一标识符
    public string key;


    //超时时间
    public float time;


    //当前数到的时间
    public float curTime;


    //定时器的类型 
    public ETimerType type;


    //回调函数
    public Action action;
    //
    public bool isDead;


    public Timer(string key, float time, ETimerType type, Action action)
    {
        curTime = 0;
        this.key = key;
        this.time = time;
        this.type = type;
        this.action = action;
        isDead = false;
    }
}



public class TimerMgr
{

    static TimerMgr sInstance = null;
    public static TimerMgr Instance
    {
        get
        {
            if (sInstance == null)
            {
      
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值