OK so something I noticed happen recently, is that the player self-heals himself everytime we return to the game from a saved file (in fact, if I’m not mistaken, he basically plays the “level up” event particle system, which is only played by levelling the player up)
How do I fix this? I just don’t want the player levelling himself up (or his health at the very least) every time we return to the game…
if it helps, this is my ‘RestoreFromJToken()’ and ‘UpdateState()’ (oddly enough, the enemy doesn’t do that, just the player…) functions, from my ‘Health.cs’ script:
private void UpdateState() {
// This function is the Death function of the Player/Enemy, just renamed:
Animator animator = GetComponent<Animator>();
if (!animator) return;
// if we weren't dead last frame, but now we died, then trigger the animator, cancel actions, update your death, and Invoke 'onDie()'
if (!wasDeadLastFrame && IsDead()) {
// animator.SetTrigger("die");
// Cancelling all executable scripts if we die
GetComponent<ActionSchedular>().CancelCurrentAction();
// Invoke death ONLY IF THE PLAYER WASN'T DEAD BEFORE, BUT NOW HE'S BEEN RECENTLY KILLED (nah, don't do that. It glitches the Item Drops...):
// onDie?.Invoke();
}
if (wasDeadLastFrame && !IsDead()) {
// if he was dead, but now has been respawned, reset the animator using 'Rebind()' function
onResurrection.Invoke();
animator.Rebind(); // Reset the Animator entirely, and start from scratch
}
// Updating the Death of whoever carries this script (Player/Enemy):
wasDeadLastFrame = IsDead();
}
public void RestoreFromJToken(JToken state) {
healthPoints.value = state.ToObject<float>();
UpdateState();
}