Minimal code from BoardScript.cs
public class BoardScript : MonoBehaviour {
private float angle;
private static BoardScript instance;
void Awake() {
if (instance == null) {
instance = this;
}
else if (instance != this) {
Destroy(gameObject);
}
}
Start(){
angle = 0.5f;
}
Update(){
Debug.Log("angle = " + angle); // logged angle never changes.
Debug.Log("GetAngle() returns " + GetAngle()); // also never changes...
}
public SetAngle(float arg) {
angle = arg;
Debug.Log("angle set to " + angle);
// Above always logs new angle as called fron Settings.cs.
}
private float GetAngle() { // only use is for debugging this issue.
Debug.Log("angle is " + angle); // Does not log newly set angle.
return angle;
}
}
Minimal code Settings.cs
private GameObject theBoard;
public void SetBoardAngule(float arg) {
theBoard.GetComponent<BoardScript>().SetAngle(arg);
Debug.Log("Settings - SetAngle to " + arg); // Logs correct angle.
}
The update function logs "angle = 0.5" no matter what it gets set to in method SetAngle(). This seems terribly simple to me. What am I doing incorrectly?
GetAngleon the same instance, that you are callingSetAngleon? You should share the code, where you callSetAngle, tootheBoard.GetComponent<BoardScript>().SetAngle(arg);tryBoardScript.instance.SetAngle(arg)instanceis private. The singleton should be public for access though.BoardScript.instance.function