- Home /
Question by
thefrogeitan · Feb 23, 2020 at 05:40 AM ·
scripting problemerror
Trying to Invoke method: EndGame.gm.End couldn't be called.
i want to reastart the game in 2 sec dealy and is give me a erorr. this is my code
public class EndGame : MonoBehaviour
{
public GameMengement gm;
public GameObject blood;
private void OnTriggerEnter2D(Collider2D col)
{
if(col.tag == "Obstcle")
{
Instantiate(blood, transform.position, Quaternion.identity);
Invoke("gm.End", 2f);
}
}
}
Comment
Answer by joemane22 · Feb 23, 2020 at 07:37 AM
It would probably be better to use a coroutine for this case.
IEnumerator EndGame(float wait)
{
yield return new WaitForSeconds(wait);
gm.End();
}
private void OnTriggerEnter2D(Collider2D collision)
{
StartCoroutine(EndGame(2f));
}
Your answer
Follow this Question
Related Questions
Problem with attaching scripts to objects 1 Answer
Maintain local transform.rotation.y when updating transform.up? 2 Answers
Array Out of Index (When it Really is not??) 1 Answer
How to store a Transform[,] grid in an ArrayList? 2 Answers
Help with editing array from inside functions for PID controller (C#)[Fixed] 1 Answer