So i have made myself a respawn script,problem is that when i trigger it ,my player jumps to that position locks in place,and it takes some seconds before it gets freed. here’s the code i put togheter;
using UnityEngine;
using System.Collections;
public class IFIHADACAT : MonoBehaviour {
public Vector3 spawnpoint;
public float life;
public bool respawn;
public Vector3 checkpoint;
// Use this for initialization
void Start () {
life = 1;
respawn = false;
}
void RespawnPlayer () {
transform.position = spawnpoint;
}
void OnCollision2D (Collider2D col){
if (col.gameObject.tag == "CheckPoint")
spawnpoint = checkpoint;
}
// Update is called once per frame
void Update () {
if (life == 0) {
respawn = true;
}
if (respawn) {
StartCoroutine (riperino ());
}
}
IEnumerator riperino() {
Debug.Log ("ded");
yield return new WaitForSeconds (4);
Debug.Log ("ugh,you again?");
RespawnPlayer ();
respawn = false;
}
}
P.s. i also want to move my spawn point to my check point but i don’t know why it doesn’t work.Thanks in advance.