如何在我的启动函数中启动计时器而不是update() [英] How do I get my timer to start in my start function instead of update()
本文介绍了如何在我的启动函数中启动计时器而不是update()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当你按下btn换Lv1时我有一些关闭门的过渡,
我明白定时器是在更新方法中,所以当它到达时0它会加载我的等级
然而我想说我的
I have a transition with some doors closing when you press a btn for Lv1,
I understand that the timer is in the update method so that when it reached 0 it will load my level
However I'm trying to say when my
private void StartDoor()
功能
被调用然后启动此延迟加载计时器!当达到0然后加载该级别。
not此脚本启动后立即启动此计时器。
我非常感谢任何帮助,我对批评或反馈不敏感。
我尝试过:
function
is called to then START this delay to load timer! and when that reaches 0 then load the level.
not Have this timer start as soon as this script starts.
I really appreciate any help given and I am not sensitive to criticism or feedback.
What I have tried:
using UnityEngine;
using Spine.Unity;
using Spine;
using UnityEngine.SceneManagement;
public class DoorTransition : MonoBehaviour
{
public SkeletonAnimation SkelAnim;
[SpineAnimation]
public string DoorClose;
[SerializeField]
private float delayBeforeLoading = 10f;
void Awake()
{
SkelAnim = GetComponent<SkeletonAnimation>();
}
private void StartDoor()
{
SkelAnim.state.SetAnimation(0, DoorClose, false);
if (delayBeforeLoading <=0)
SceneManager.LoadScene("LevelOne");
}
private void Update()
{
delayBeforeLoading -= Time.deltaTime;
}
}
推荐答案
这对于我是b $ b
This has worked for me
using UnityEngine;
using Spine.Unity;
using Spine;
using UnityEngine.SceneManagement;
public class DoorTransition : MonoBehaviour
{
public SkeletonAnimation SkelAnim;
[SpineAnimation]
public string DoorClose;
bool TimerStarted = false;
private float _timer = 0f;
public float LoadLevelDelay = 1f;
void Awake()
{
SkelAnim = GetComponent<SkeletonAnimation>();
}
private void StartDoor()
{
TimerStarted = true;
SkelAnim.state.SetAnimation(0, DoorClose, false);
}
void Update()
{
if (TimerStarted)
{
_timer += Time.deltaTime;
if (_timer >= LoadLevelDelay)
{
SceneManager.LoadScene("LevelOne");
}
}
}
}
这篇关于如何在我的启动函数中启动计时器而不是update()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文