Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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()
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;
    
    }


}
Posted
Updated 4-Mar-19 3:00am

1 solution

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");
            }

        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900