So I don’t know why, but when I build my game, it completely ignores a specific line of code, no matter where i put it.
(yes everything is defined, and no I’m not seeing any errors)
public void respawn()
{
Health = 100;
dead = false;
deathScreen.SetActive(false);
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
Time.timeScale = 1f;
GunScript.justUnpaused = true;
PaintGun.justUnpaused = true;
SpawnGunScript.justUnpaused = true;
DeleteGunScript.justUnpaused = true;
GravityGunScript.justUnpaused = true;
HealScript.justUnpaused = true;
GrenadeThrower.justUnpaused = true;
player.position = spawnPoint;
}
It just completely ignores player.position = spawnPoint, anyone know how to fix this?
If this works in editor and not in build then spawnPoint might not have serialized properly.
Add a debug statement and check output.txt in build folder.
It is a common mistake among newbie programmers to see some sort of bug, reason that “if X happened, that would explain this bug”, and then assume that X is true without looking for other things that could also explain the same symptom.
The computer randomly deciding to skip a line of code is not a plausible hypothesis. I don’t know what symptom you actually saw, but unless you stepped through this code in a debugger one line at a time and watched it jump from line 15 to line 17 without stopping on line 16, I think odds are high that you have misinterpreted the cause.
Other possibilities include:
- The variable “player” doesn’t have the value you expected
- The variable “spawnPoint” doesn’t have the value you expected
- This whole function isn’t running at the time that you expected it to run
- Something else changed the player’s position after this code ran
- A runtime exception was thrown on an earlier line, causing the function to end prematurely (unlikely; nothing in the code you posted is likely to throw an exception)