- Home /
My Player can't move after respawning, help?
So basically i have this script that is supposed to spawn the player at the checkpoint after it collides with the enemy. Only problem is, after it spawns at the checkpoint position the player is unable to move. Any help is greatly appreciated.
using UnityEngine; using System.Collections;
public class LevelManager : MonoBehaviour {
public bool playerIsDead;
public GameObject player;
public GameObject currentCheckpoint;
public new Vector2 checkpointPosition;
// Use this for initialization
void Start () {
checkpointPosition = currentCheckpoint.transform.position;
playerIsDead = false;
}
// Update is called once per frame
void Update ()
{
if (PlayerControl.isDead == true)
{
playerIsDead = true;
}
if(playerIsDead == true)
{
player.transform.position = checkpointPosition;
playerIsDead = false;
}
}
}
As a rule of thumb, avoid having variables for the same piece of data in multiple classes/instances unless there's a real reason for it. Now you have 2 booleans for marking the player dead.
Answer by allenallenallen · Jan 02, 2016 at 08:37 AM
Since you didn't give us the code from PlayerControl script, we can't help you that much.
I'm assuming that PlayerControl.isDead is never set to false after your player dies so it keeps being teleported to the checkpoint every frame. As long as your character is constantly being teleported to the checkpoint, you can't move it.
One small thing:
public new Vector2 checkpointPosition;
should be
public Vector2 checkpointPosition;
Your answer
Follow this Question
Related Questions
Checkpoint Question 0 Answers
Spawning Script Error 1 Answer
Having camera attack upon spawning player? 1 Answer
ai spawning please help 0 Answers
Multiplayer. Destroying player object on Host/Server 2 Answers