unity中的Updata会在每一帧都执行,如果项目中Updata不用每帧都执行,可以试一下该方法,将Updata使用频率降低。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class demo : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Time.frameCount % 6 == 0)
{
DoDemoThing();
}
}
private void DoDemoThing()
{
Debug.Log("aaa");
}
}
只需要在Updata中使用此方法,即可在每6帧执行一次,如果还有点短可以将6这个数字修改一下。
使用这种方法可以减少Updata执行的次数,减少运行消耗。