Hi there!
I’m not sure when this issue started to occur, but I noticed it after finishing this lecture.
If I save the game, kill an enemy and press L to load → the enemy won’t revive even though he does load back with the proper health points (as the image shows below).
It’s important to note that if I save my game, kill an enemy, stop the game completely and then pressing play again → the enemy IS standing and alive as he should be.
Attaching a screenshot:
And here is my Health script and SavingWrapper:
using UnityEngine;
using RPG.Saving;
using RPG.Stats;
using RPG.Core;
namespace RPG.Attributes
{
public class Health : MonoBehaviour, ISaveable
{
[SerializeField] float healthPoints = -1f;
bool isDead = false;
private void Start()
{
if (healthPoints < 0)
{
healthPoints = GetComponent<BaseStats>().GetStatFromProgression(Stat.Health);
}
}
public bool IsDead()
{
return isDead;
}
public void TakeDamage(GameObject instigator, float damage)
{
healthPoints = Mathf.Max(healthPoints - damage, 0);
if (healthPoints == 0 && isDead == false)
{
Die();
AwardExperience(instigator);
}
}
public float GetPercenetage()
{
return 100 * (healthPoints / GetComponent<BaseStats>().GetStatFromProgression(Stat.Health));
}
private void Die()
{
if (isDead) return;
isDead = true;
GetComponent<Animator>().SetTrigger("die");
GetComponent<ActionScheduler>().CancelCurrentAction();
}
private void AwardExperience(GameObject instigator)
{
Experience experience = instigator.GetComponent<Experience>();
if (experience == null) return;
experience.GainExperience(GetComponent<BaseStats>().GetStatFromProgression(Stat.ExperienceReward));
}
public object CaptureState()
{
return healthPoints;
}
public void RestoreState(object state)
{
healthPoints = (float)state;
if (healthPoints <= 0)
{
Die();
}
}
}
}
using RPG.Saving;
using System.Collections;
using UnityEngine;
namespace RPG.SceneManagement
{
public class SavingWrapper : MonoBehaviour
{
const string defaultSaveFile = "save";
[SerializeField] float fadeInTime = 2f;
IEnumerator Start()
{
Fader fader = FindObjectOfType<Fader>();
fader.FadeOutImmediate();
yield return GetComponent<SavingSystem>().LoadLastScene(defaultSaveFile);
yield return fader.FadeIn(fadeInTime);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.L))
{
Load();
}
if (Input.GetKeyDown(KeyCode.S))
{
Save();
}
if (Input.GetKeyDown(KeyCode.Delete))
{
Delete();
}
}
public void Load()
{
//call to the saving system load
GetComponent<SavingSystem>().Load(defaultSaveFile);
}
public void Save()
{
GetComponent<SavingSystem>().Save(defaultSaveFile);
}
public void Delete()
{
GetComponent<SavingSystem>().Delete(defaultSaveFile);
}
}
}
If anymore of my code is required please let me know and I’ll paste it as soon as I can.
Thank you!