I have this code, where RoomId ought to be getting updated with every click of an option:
public class textUpdateScript : MonoBehaviour {
private int RoomId;
private int NorthOptionRoomId;
private int EastOptionRoomId;
private int WestOptionRoomId;
void Awake () {
UpdateText (0);
SetOptions (0);
}
public void HandleOptionClick (){
SetRoomId ();
UpdateText (RoomId);
SetOptions (RoomId);
}
private void SetRoomId () {
String name = this.gameObject.name;
if (name == "OptionEast") {
RoomId = EastOptionRoomId;
} else if (name == "OptionWest") {
RoomId = WestOptionRoomId;
} else if (name == "OptionNorth") {
RoomId = NorthOptionRoomId;
}
}
private void SetOptions(int roomNumber) {
TextAsset jsonText = Resources.Load("rooms") as TextAsset;
Room[] room = JsonHelper.FromJson<Room> (jsonText.text);
NorthOptionRoomId = setOptionRoomId (room [roomNumber].northOptionroomId);
EastOptionRoomId = setOptionRoomId (room [roomNumber].eastOptionroomId);
WestOptionRoomId = setOptionRoomId (room [roomNumber].westOptionroomId);
}
private int setOptionRoomId (string roomOptionId) {
int i;
return i = Int32.TryParse (roomOptionId, out i) ? i : -1;
}
...
}
But what seems to be happening is that the RoomId variable only maintains its updated state until I call the HandleOptionClick method again - when I do, RoomId is always zero and I’m not sure why.
I’m new to C#, but have searched for answers on the issue and couldn’t find a solution, so wondering if it’s something to do with my code…