Ok I’m making the UI of a game, I created two classes one is the parent (UIInteract.cs) and another is the inheritance (UIIteractIcon). There is a protected boolean variable named ShowInteract. The flow is when I switch the ShowInteract to true value, the GUI of the UIIteractIcon should show on the game screen.
public class UIInteract : MonoBehaviour {
protected INVENTORY.SingleItem currentItemInteract;
protected int PerformSlot;
protected bool ShowInteract = true;
// Use this for initialization
void Awake () {
}
public bool Show{
set{ ShowInteract = value;}
get{ return ShowInteract;}
}
public void StartInteract(INVENTORY.SingleItem InteractItem, int slotNumber){
theSlot = slotNumber;
currentItemInteract = InteractItem;
Show = false;
}
}
public class UIInteractIcon : UIInteract {
// private bool canShow;
void OnGUI(){
// canShow = ShowInteract;
if (ShowInteract) {
scaleFactor.x = (float)(Screen.width) / _PARAMETERS.MaxScreenWidth;
scaleFactor.y = (float)(Screen.height) / _PARAMETERS.MaxScreenHeight;
GUI.matrix = Matrix4x4.TRS (new Vector3 (0, 0, 0), Quaternion.identity, new Vector3 (scaleFactor.x, scaleFactor.y, 1));
// Debug.Log("Show interaction menu");
GUI.BeginGroup(new Rect(687,274,535,400),theSkin.box);
if(currentItemInteract.Equals(UIItemList.Dagger)){
GUI.Box(new Rect(0,0,535,400),"",theSkin.GetStyle("Dagger"));
}else if(currentItemInteract.Equals(UIItemList.Avens)){
GUI.Box(new Rect(0,0,535,400),"",theSkin.GetStyle("Avens"));
}else if(currentItemInteract.Equals(UIItemList.RustyDagger)){
GUI.Box(new Rect(0,0,535,400),"",theSkin.GetStyle("RustyDagger"));
}else if(currentItemInteract.Equals(UIItemList.Germander)){
GUI.Box(new Rect(0,0,535,400),"",theSkin.GetStyle("Germander"));
}
GUI.EndGroup();
}
}
}
However the case is when I called the function StartInteract() in UIInteract.cs. The GUI doesnt show in the game. I checked the value of ShowInteract in UIInteract.cs. It has been updated to true. But the value I get from the inheritance class UIInteractIcon is still false. I have no idea why it likes this. Thanks a lot if anyone can help.!!