I have 2 scene, one is the main menu and one is the main game. in the game i place may save point and in the main menu i have a 2 button, 1 is new game and 1 is continue. what i already did is i can play the new game simple by loading the second scene, but for continue i cant load the previous save point by using playerprefs. only the continue button in my game is the one not functioning right
this is my code for the save point
public class save : MonoBehaviour
{
public bool triggered;
public Animator anito;
void OnTriggerEnter2D(Collider2D cut)
{
if (cut.gameObject.CompareTag("Player"))
{
anito.SetBool("save", true);
PlayerPrefs.SetFloat("PlayerX", transform.position.x);
PlayerPrefs.SetFloat("PlayerY", transform.position.y);
PlayerPrefs.SetFloat("PlayerZ", transform.position.z);
PlayerPrefs.SetInt("Saved", 1);
PlayerPrefs.Save();
triggered = true;
}
}
void OnTriggerExit2D(Collider2D cut)
{
if (cut.gameObject.CompareTag("Player"))
{
anito.SetBool("save", false);
triggered = false;
}
}
}
and this is for the continue button this code work if the continue button is in the same scene. obj2 is the player object
public void continuegame()
{
obj2.transform.position = new Vector3(PlayerPrefs.GetFloat("PlayerX"), PlayerPrefs.GetFloat("PlayerY"), PlayerPrefs.GetFloat("PlayerZ"));
obj3.SetActive(false);
obj4.SetActive(true);
}