Save enemy data whether he is dead or not ?
I have two enemies"Cubes" in my scene and player"Hero". What i'm trying to do is make a checkpoint. if i saved my game and then killed one enemy, this enemy should return when l load my save AND this is not happen with me. This is simple script i wrote it to save enemy life, attach it with my player.
using UnityEngine; using System.Collections; using UnityEngine.UI; public class chickpoint : MonoBehaviour {
public DeadLife _checklife;
public void Load_Chickpoint() { PlayerPrefs.SetFloat("dead",_checklife.O_Life); Debug.Log("save game"); } public void Save_Chickpoint() { float dead = PlayerPrefs.GetFloat("dead"); Debug.Log("load game"); }
}
////////////////////////////////////////////
And here is the enemy script
using UnityEngine; using System.Collections; public class DeadLife : MonoBehaviour { public float O_Life = 100f; // Use this for initialization void Start () { } // end start // Update is called once per frame void checkLive () {
if(O_Life < 1f)
{
gameObject.SetActive(false); // dead enemy
}
if(O_Life > 1f)
{
gameObject.SetActive(true); // if i load my save and my enemy healthy above 1, is should become full 100.
O_Life =100f;
}
}
void OnTriggerStay(Collider collision) {
if (collision.gameObject.CompareTag("Hero"))
{
O_Life -= 0.50f;
}
}
}
So, where is my problem ?
To me it seems like you are setting the float when loading and getting the float when saving which seems the wrong order.
Your answer
Follow this Question
Related Questions
Most efficient way to store information in an inspector dropdown menu? 0 Answers
What is the best way to achieve local database for mobile? 0 Answers
Some help with Data Save/Load would be most appreciated 3 Answers
Does Unity Services store bought items when using IAP? 0 Answers
Save multiple inputs for one item and print out all items 0 Answers