Hello all I’ve been looking at some posts and tutorials about how to get (in this case a spike) to kill a character and then respawn, but unfortunately haven’t had any luck. I have placed this script below onto my character but when it hits the spikes nothing happens. I am unsure if I am meant to be putting a component or script onto the spikes, whether I am doing something wrong with the code or just doing the entire process wrong any help would be greatly appreciated!
using UnityEngine;
public class PlayerDie : MonoBehaviour
{
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.name == “Spikes”)
{
StartCoroutine(DieAndRespawn());
}
}
IEnumerator DieAndRespawn()
{
GetComponent().enabled = false;
yield return new WaitForSeconds(2.0f);
transform.position = new Vector3(-1.522073f, -2.205271f, 0.0f);
transform.rotation = Quaternion.identity;
GetComponent().enabled = true;
}
}