Game Doesn't Work Properly in Editor but Works When Built
I am working on a game where the player can record there movement and create a clone what follows this recorded movement. What happens is the player presses the record button and gets teleported to the start of the level. When the player is done recording there movement, they press record again, teleporting them back to where they where when they first pressed record. In addition to the teleportation, a variable called, isRecording, is true when the player is recording and false when not. When I test this in the editor, the isRecording variable toggles back and forth correctly, however, the player won't always teleport. These problems only appear when playing the game in the editor, and disapear when I play the build of the game. Why does this happen, and how can I fix this so I can test my game in the editor.
public class PlayerMovement : MonoBehaviour
{
public KeyCode recordButton;
public Vector3 spawn;
bool isRecording = false;
Vector3 recordStartPosition;
void Start()
{
spawn = transform.position;
}
void Update()
{
if (Input.GetKeyDown(recordButton))
{
if (isRecording) StopRecording();
else StartRecording();
}
}
void StartRecording()
{
isRecording = true;
recordStartPosition = transform.position;
transform.position = spawn;
}
void StopRecording()
{
isRecording = false;
transform.position = recordStartPosition;
}
}
Your answer
Follow this Question
Related Questions
Input.GetMouseButtonDown not working in Play mode 0 Answers
Extremely Low FPS in Editor, smooth in Build. how to fix? 3 Answers
Controls do not transfer from Editor to Build 0 Answers
Editor crashes immediately 0 Answers
Slow unity things 0 Answers