Hi i want my player to wait 5 sec before he respawns but with this script, the game "teleports" him directly when he touched the collider.. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class RetourA0 : MonoBehaviour { public GameObject personnage; public GameObject start; // Use this for initialization void Start () { } void OnTriggerEnter (Collider A) { if (A.gameObject.tag == "Player") { StartCoroutine ("Pause"); A.transform.position = start.transform.position; } } IEnumerator Pause (){ Debug.Log ("mabeut debut"); yield return new WaitForSeconds (5f); Debug.Log ("mabeut FIN"); } void Update () { } } Thanks a lot for your help
You need to put the teleport part at the end of your coroutine. Coroutines don't pause your code. For your code, it will run the start part of the coroutine and then yield for 5 secs, which allows other code to run. Basically when it hits the yield, your teleport gets to trigger. After 5 secs, the rest of the coroutine gets a chance to run.
That isn't going to work as the Pause doesn't know what A is. The gameobject will need to be passed to the coroutine. @Sabakey Also note you should use the method version of starting your coroutine as you can easily pass parameters that way vs the string call. Code (CSharp): StartCoroutine(Pause()); //Method version StartCoroutine(Pause(A)); //Method version with param IEnumerator Pause (GameObject A) //Pass the gameobject to your coroutine.