Hey guys, struggling to get this script to work properly.
Just want a 2 second delay on Earthquake
Any Ideas
using UnityEngine;
public class EarthQuakeTrigger : MonoBehaviour
{
public vp_FPPlayerEventHandler PlayerEventHandler = null;
void Awake()
{
PlayerEventHandler =
(vp_FPPlayerEventHandler)FindObjectOfType(typeof(vp_FPPlayerEventHandler));
}
void OnTriggerEnter (Collider other) {
StartCoroutine(StartQuake());
IEnumerator StartQuake(){
}
yield return new WaitForSeconds(2);
PlayerEventHandler.Earthquake.TryStart(new Vector3(0.2f, 0.2f, 5.0f));
}
}
Is the actual code you’ve pasted what you’re trying to use, the way you have it currently the IEnumerator is inside OnTriggerEnter.
void OnTriggerEnter(Collider other){
Debug.Log("2 seconds until earthquake");
StartCoroutine(StartQuake());
}
IEnumerator StartQuake(){
yield return new WaitForSeconds(2);
Debug.Log("Earthquake starting");
PlayerEventHandler.Earthquake.TryStart (new Vector3(0.2f, 0.2f, 5.0f));
}
That will start the coroutine after two seconds, though in what you’ve posted this can be called more than once.