Hi everybody, I’m new with coding and I’m having a difficult time with my GUI.window. My goal is to have a window change its size relative to another variable called from another script. While this is going on, the window is also able to be dragged around the screen. I have tried and tried, but alas no luck. If anyone is able to help me with this that would be great. Here’s the code:
public class ScriptOne : MonoBehaviour {
private Rect _InventoryWindowRectangle;
private const int INVENTORY_WINDOW_ID = 1;
private int ButtonSizeW = Screen.width / 16;
private int ButtonSizeH = Screen.height / 16;
public int _InvtRows;
public int _invtCols;
void OnGUI() {
if(_DisplayInventoryWindow == false) {
_scriptTwo = (ScriptTwo)FindObjectOfType(typeof(ScriptTwo));
_InventoryWindowRectangle = GUI.Window(INVENTORY_WINDOW_ID, _scriptTwo.INVwinre, InventoryWindow, _scriptTwo.nameBag);
}
}
public void InventoryWindow(int id) {
_scriptTwo = (ScriptTwo)FindObjectOfType(typeof(ScriptTwo));
_InvtRows = _scriptTwo.yBag;
_invtCols = _scriptTwo.xBag;
for(int y = 0; y < _InvtRows; y++) {
for(int x = 0; x < _invtCols; x++) {
GUI.Button(new Rect( (Screen.width / 256) + (x * ButtonSizeW), (Screen.height / 32) + (y * ButtonSizeH), ButtonSizeW, ButtonSizeH), (x + y *_invtCols).ToString());
}
}
GUI.DragWindow(); //This used to work until I added the info from ScriptTwo
}
}
//Second Script Function
public class ScriptTwo : MonoBehaviour {
void CheckBag() { //I think this is where the problem is since im calling the location
bagType = OtherScript.bagType; // for the rectangle at(10,10,...,...)
if(bagType == 0) {
INVwinre = new Rect(10,10,(Screen.width / 4) + (Screen.width / 128), (Screen.height * 3) / 32);
nameBag = "Bag1";
yBag = 1;
xBag = 4;
}
if(bagType == 1) {
INVwinre = new Rect(10,10,(Screen.width / 4) + (Screen.width / 128), (Screen.height * 5) / 32);
nameBag = "Bag2";
yBag = 2;
xBag = 4;
}
}
}
I have noted where i think the error is occurring in ScriptTwo, at least where the window is not moving , that is my guess but I have not figured a way around it.