- Home /
Why isn't the window draggable?
I want to make this window draggable, why isn't it dragging? Heres the code:
public class ButtonsAtTop : MonoBehaviour {
public Texture LogOutTexture;
public Texture Shop;
public Texture Inventory;
public Texture Friends;
public Texture Chat;
public Texture CharacterCustom;
public Rect WindowSize = new Rect (700f,700f,1000f,1000f);
bool displayWindowForShop=false;
void OnGUI()
{
if (GUI.Button (new Rect (Screen.width - 50, 0, 50, 50), LogOutTexture))
{
PhotonNetwork.Disconnect();
}
if (GUI.Button (new Rect (Screen.width - 100, 0, 50, 50), Shop))
{
displayWindowForShop=!displayWindowForShop;
}
if(GUI.Button (new Rect (Screen.width - 150, 0, 50, 50),Inventory))
{
}
if(GUI.Button (new Rect (Screen.width - 200, 0, 50, 50),Friends))
{
}
if(GUI.Button (new Rect (Screen.width - 250, 0, 50, 50),Chat))
{
}
if(GUI.Button (new Rect (Screen.width - 300, 0, 50, 50),CharacterCustom))
{
}
if (displayWindowForShop)
{
GUI.Window(0, new Rect(Screen.width-750,(Screen.height/2)-250,500,500), ShopWindow, "Shop Window");
}
}
void ShopWindow(int id)
{
GUI.DragWindow ();
}
void OnDisconnectedFromPhoton()
{
Application.LoadLevel ("SciFi Level");
}
}
Comment
Answer by maccabbe · Feb 26, 2015 at 07:51 PM
This is because you never update the rect of the window. Try using the following:
using UnityEngine;
public class ButtonsAtTop : MonoBehaviour {
public Rect showWindowRect;
bool displayWindowForShop=false;
void Start() {
displayWindowForShop=true;
showWindowRect=new Rect(Screen.width-750, (Screen.height/2)-250, 500, 500);
}
void OnGUI() {
if(displayWindowForShop) {
showWindowRect=GUI.Window(0, showWindowRect, ShopWindow, "Shop Window");
}
}
void ShopWindow(int id) {
GUI.DragWindow();
}
}
i get it, but i did it and it isn't workiing properly, whats wrong?:
public class ButtonsAtTop : $$anonymous$$onoBehaviour {
public Texture LogOutTexture;
public Texture Shop;
public Texture Inventory;
public Texture Friends;
public Texture Chat;
public Texture CharacterCustom;
public Rect WindowSize = new Rect (700f,700f,1000f,1000f);
bool displayWindowForShop=false;
public Rect showWindowRect;
void start()
{
showWindowRect=new Rect(Screen.width-750, (Screen.height/2)-250, 500, 500);
}
void Update()
{
}
void OnGUI()
{
if (GUI.Button (new Rect (Screen.width - 50, 0, 50, 50), LogOutTexture))
{
PhotonNetwork.Disconnect();
}
if (GUI.Button (new Rect (Screen.width - 100, 0, 50, 50), Shop))
{
displayWindowForShop=!displayWindowForShop;
}
if(GUI.Button (new Rect (Screen.width - 150, 0, 50, 50),Inventory))
{
}
if(GUI.Button (new Rect (Screen.width - 200, 0, 50, 50),Friends))
{
}
if(GUI.Button (new Rect (Screen.width - 250, 0, 50, 50),Chat))
{
}
if(GUI.Button (new Rect (Screen.width - 300, 0, 50, 50),CharacterCustom))
{
}
if (displayWindowForShop)
{
showWindowRect=GUI.Window(0, showWindowRect, ShopWindow, "Shop Window");
}
}
void ShopWindow(int id)
{
GUI.DragWindow ();
Debug.Log ("Should be working");
}
void OnDisconnectedFromPhoton()
{
Application.LoadLevel ("SciFi Level");
}
}
i tried to apply this to lots of buttons but i get a strange error:
ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint
Aborting
here is the code causing the error
public class Room$$anonymous$$echanics: $$anonymous$$onoBehaviour {
public string InputField;
public ArrayList ListOFGames=new ArrayList();
void Start()
{
}
void OnGUI() {
InputField = GUI.TextField(new Rect((Screen.width / 2) - 125, Screen.height / 100, 250, 25), InputField);
foreach(RoomInfo room in PhotonNetwork.GetRoomList())
{
if (InputField != "")
{
if (room.name.ToString().Contains(InputField))
{
ListOFGames.Add(room.name);
if(ListOFGames.ToArray().Length > 10)
{
}
if (GUI.Button(new Rect((Screen.width / 2) - 125, (ListOFGames.IndexOf(room.name) * 50)+ (Screen.height/100)+25 , 250, 50), room.name))
{
PhotonNetwork.JoinRoom(room.name);
}
}
else
{
ListOFGames.Clear();
}
}
else
{
ListOFGames.Clear();
}
}
}
void OnJoinedRoom()
{
Application.LoadLevel ("Room]");
}
}
Your answer
Follow this Question
Related Questions
unity gui.window in a class - monobehaviour error using new keyword 1 Answer
Zoom effect in EditorGUI Windows 0 Answers
Window isn't opening 1 Answer
GUI: Windows inside Windows 1 Answer