I’ve run into a problem that’s been bothering me a little bit.
I’m sure the cause of it is something very simple, but I can’t seem to think of anything.
My scene currently has a set of spikes and a player. Whenever the player collides with the spikes, it’s supposed to respawn at a checkpoint. I’ve used the following scripts for this:
KillPlayer (attached to Spikes)
public LevelManager levelManager;
void Start ()
{
levelManager = FindObjectOfType<LevelManager>();
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.name == "player")
{
levelManager.RespawnPlayer();
}
}
LevelManager (attached to empty gameobject in scene)
public GameObject currentCheckpoint;
private PlayerController player;
void Start ()
{
player = FindObjectOfType<PlayerController>();
}
public void RespawnPlayer()
{
Debug.Log("Player respawned.");
player.transform.position = currentCheckpoint.transform.position;
}
I know this script works, because when I move the player into the spikes, the camera moves back to the position of the checkpoint.
However, after this happens, I can’t see my player anymore.
After some research I found that the problem might have something to do with the Sprite Renderer’s Sorting Layer being set on default, but I’m too much of a newbie to know what I’m supposed to change to fix this.
To be sure, here’s a few screenshots.