This question was
closed Apr 25, 2018 at 10:46 AM by
tormentoarmagedoom for the following reason:
The question is answered, right answer was accepted
[SOLVED] I need to delay an argument! under TakeOff() Method.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NavigationObject : MonoBehaviour {
[SerializeField]
private GameObject[] _gui;
[SerializeField]
private MovingObjects _movingObjects;
[SerializeField]
private LevelManager _levelManager;
private void OnTriggerEnter2D (Collider2D other)
{
if (other.tag == "Player")
{
_gui[0].SetActive(true);
}
}
private void OnTriggerStay2D (Collider2D other)
{
if (other.tag == "Player" && Input.GetKeyDown(KeyCode.E))
{
ActivatingConsole();
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.tag == "Player")
{
_gui[0].SetActive(false);
}
}
private void ActivatingConsole()
{
_gui[1].SetActive(true);
Time.timeScale = 0.0f;
}
public void TakeOff()
{
_gui[1].SetActive(false);
Time.timeScale = 1.0f;
_movingObjects.ShipLeaving();
//I want this next argument to be delayed by 5 secounds! <---------- THIS ONE!
_levelManager.LoadNextLevel();
}
public void TakeOffReject()
{
_gui[1].SetActive(false);
Time.timeScale = 1.0f;
}
}
Comment
I am leaving this up so if anyone needs help @Harinezumi was awesome!
Best Answer
Answer by Harinezumi · Apr 03, 2018 at 08:33 AM
Start a coroutine and yield on a new WaitForSeconds(5). Something like this:
// in TakeOff() replace _levelmanager.LoadNextLevel() with this:
StartCoroutine(DelayLoadLevel());
private IEnumerator DelayLoadLevel() {
yield return new WaitForSeconds(5);
_levelManager.LoadNextLevel();
}