Hello Guys, I’m making a 2D game , and I am having some trouble making my player respawn when he falls.
I have a script attached to my player, that makes basically 3 things: Kill the player when he falls off a platform and touches an invisible Collider2D that detects the player, create a new one on the spawning point and then move the camera towards the new player.
But I can’t get that going. Whenever my player dies, the camera moves towards the spawning point and I can see that a Character(Clone) is created, but I can’t see him on the Game window (Only the camera moving if i move my player) and he appears visible on the Scene Window as well…
Here’s the code:
public class Respawn : MonoBehaviour {
public GameObject character; //a prefab of my player will be attached to the script
public Transform spawnPoint; // an empty gameObject will act as the spawnPoint
void OnTriggerEnter2D(Collider2D coll){
Destroy (coll.gameObject);
if (character) {
GameObject p = Instantiate (character, spawnPoint.position, Quaternion.identity) as GameObject;
CamController cam = Camera.main.gameObject.GetComponent<CamController> (); //The script that mo
cam.target = p.transform;
}
}
}
Hope you can help me!