Question by
LMJ5631 · Dec 11, 2018 at 03:20 AM ·
waitforseconds
delay time to trigger the action from OnTriggerStay2D using switch statement
I am failing the call the time to delay the action for changing scene.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class needle : MonoBehaviour {
public AutoGenerateDecision _spinner;
public Text scoretext;
private float timer = 15f;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ( )
{
}
void OnTriggerStay2D(Collider2D col)
{
// timer -= Time.deltaTime;
//if (timer <= 0)
if (!_spinner.isStoped)
return;
scoretext.text = col.gameObject.name;
switch (col.gameObject.name)
{
case "POT1":
SceneManager.LoadScene("goodchoice");
break;
case "POT2":
SceneManager.LoadScene("goodchoice");
break;
case "POT3":
SceneManager.LoadScene("goodchoice");
break;
case "POT4":
SceneManager.LoadScene("goodchoice");
break;
case "WATER1":
SceneManager.LoadScene("wrongchoice");
break;
case "WATER2":
SceneManager.LoadScene("wrongchoice");
break;
case "WATER3":
SceneManager.LoadScene("wrongchoice");
break;
case "WATER4":
SceneManager.LoadScene("wrongchoice");
break;
}
Debug.Log("Before coroutine call");
StartCoroutine(load());
Debug.Log("After coroutine call");
}
IEnumerator load()
{ while (true) { Debug.Log("In Coroutine Before Wait"); yield return new WaitForSeconds(50); Debug.Log("In Coroutine After Wait"); } } }
Comment
Your answer
Follow this Question
Related Questions
Waiting for fading to end before switching scenes 0 Answers
C# Wait time not working 1 Answer
Problem with wait for seconds when my game is paused. 0 Answers
Trying to add a delay to an Instantiate in a For Loop 0 Answers
C# waitForSeconds Question 1 Answer