- Home /
Question about different on running method in [ContextMenu("xxx")] and onClick() in UI Button
Hi guys, i've experienced some weired issue for my SAVELOAD. When i use [ContextMenu("xxx")] to run my method i can immediatetly go to the position i stored. But when i use onClick() in UI Button to call my method i cant move my player's position (I'm using this video to create my saveLoad https://www.youtube.com/watch?v=f5GvfZfy3yk&t=708s)
this is how i restore my data`using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.UI;
namespace Assets.GameSystem.SaveSystem3 { public class LevelSystem : MonoBehaviour, ISaveable { public GameObject player; public GameObject text1; public GameObject timerText; public TimerController timerController; public TriggerArea triggerArea1; public TriggerArea triggerArea2; public TriggerArea triggerArea3; [SerializeField] private string level = "Menu"; [SerializeField] public float pX; [SerializeField] public float pY; [SerializeField] public float pZ; [SerializeField] public float rX; [SerializeField] public float rY; [SerializeField] public float rZ; [SerializeField] private string achievment; [SerializeField] private bool achieve11 = false; [SerializeField] private bool achieve22 = false; [SerializeField] private bool achieve33 = false; [SerializeField] private string timer; [SerializeField] private float s; [SerializeField] private int m; [SerializeField] private int h;
public object CaptureState()
{
return new SaveData
{
level = level,
pX = player.transform.position.x,
pY = player.transform.position.y,
pZ = player.transform.position.z,
rX = player.transform.rotation.x,
rY = player.transform.rotation.y,
rZ = player.transform.rotation.z,
achievment = text1.GetComponent<Text>().text,
achieve11 = triggerArea1.achive1,
achieve22 = triggerArea2.achive2,
achieve33 = triggerArea3.achive3,
s = timerController.secondsCount,
m = timerController.minuteCount,
h = timerController.hourCount
};
}
public void RestoreState(object state)
{
var saveData = (SaveData)state;
level = saveData.level;
pX = saveData.pX;
pY = saveData.pY;
pZ = saveData.pZ;
rX = saveData.rX;
rY = saveData.rY;
rZ = saveData.rZ;
player.transform.position = new Vector3(pX, pY, pZ);
player.transform.eulerAngles = new Vector3(rX, rY, rZ);
//player.transform.position = playerPosition;
//player.transform.eulerAngles = playerRotation;
achievment = saveData.achievment;
text1.GetComponent<Text>().text = achievment;
achieve11 = saveData.achieve11;
triggerArea1.achive1 = achieve11;
achieve22 = saveData.achieve22;
triggerArea2.achive2 = achieve22;
achieve33 = saveData.achieve33;
triggerArea3.achive3 = achieve33;
s = saveData.s;
timerController.secondsCount = s;
m = saveData.m;
timerController.minuteCount = m;
h = saveData.h;
timerController.hourCount = h;
}
[Serializable]
private struct SaveData
{
public string level;
public float pX;
public float pY;
public float pZ;
public float rX;
public float rY;
public float rZ;
public string achievment;
public bool achieve11;
public bool achieve22;
public bool achieve33;
public string timer;
public float s;
public int m;
public int h;
//public Text text;
}
}
}`
Your answer

Follow this Question
Related Questions
My UI Buttons stopped working 0 Answers
How to create simple stage systems? 1 Answer
[C#] Save/Load Score stays at 0 even when changed 2 Answers
How to save field changes to scene file using ContextMenu? 1 Answer
OnClick() animation 0 Answers