Search Unity

GuI Drag window

Discussion in 'Getting Started' started by udaykumar, Sep 5, 2015.

  1. udaykumar

    udaykumar

    Joined:
    Jun 15, 2015
    Posts:
    1
    Hi ,

    I am new to unity ,i just started my scripting in unity . i am facing a problem with GUI.Dragwindow .

    I placed the GuI.Buttons inside a window with their rect positions . when i drag the window it moves on the screen but the buttons inside the GUI window are not responding.

    How can i solve this problem , can any one help me , I also posting my script here

    I would be thankful to you alot .


    using UnityEngine;
    using System.Collections;


    public class Navigation : MonoBehaviour {
    Rect windowRect = new Rect(Screen.width - 500, Screen.height-160, 290, 100);
    GUI.WindowFunction windowFunction;
    ;
    public static bool Mouseoperations = true;
    public static string StatusofNavigation;
    public static Camera currentCamera;

    public static string cameraname;
    // Use this for initialization
    void Start () {
    windowFunction = DoMyWindow;
    }

    // Update is called once per frame
    void Update () {

    if (Input.GetKeyDown ("escape")) {
    Application.LoadLevel(Application.loadedLevel);
    }
    }
    void OnGUI()
    {
    if (Mouseoperations == true) {
    windowRect = GUI.Window (10, windowRect, windowFunction, "Navigation");

    }

    }
    void DoMyWindow(int windowID)
    {

    GUIContent content = new GUIContent ();
    content.image = (Texture2D)Resources.Load ("Pan");
    content.tooltip = "Pan";


    GUIContent content1 = new GUIContent ();
    content1.image = (Texture2D)Resources.Load ("rotate");


    //content1.text = "Leather";
    GUIContent content2 = new GUIContent ();
    content2.image = (Texture2D)Resources.Load ("zoom");;
    content2.tooltip = "Zoom";

    GUIContent content3 = new GUIContent ();
    content3.image = (Texture2D)Resources.Load ("home");;
    content3.tooltip = "Reset";


    if (ViewpointsScript.camssss != null)
    {


    Camera cam = GameObject.Find (ViewpointsScript.camssss).GetComponent<Camera> ();

    if (GUI.Button (new Rect (10, 20, 50, 60), content1 )) {

    StatusofNavigation="Rotate";


    cam.gameObject.AddComponent(typeof(Rotate));
    cam.GetComponent<Rotate>().enabled=true;
    GUI.DragWindow();

    }
    if (GUI.Button (new Rect (70, 20, 50, 60), content)) {


    StatusofNavigation="pan";


    cam.gameObject.AddComponent(typeof(Pan));
    cam.GetComponent<Pan>().enabled=true;

    }
    if (GUI.Button (new Rect (130, 20, 50, 60), content2)) {

    StatusofNavigation="Zoom";


    cam.gameObject.AddComponent(typeof(Zoom));
    cam.GetComponent<Zoom>().enabled=true;



    }
    if (GUI.Button (new Rect (190, 20, 55, 60), content3)) {

    Application.LoadLevel(Application.loadedLevel);


    }
    if (GUI.Button (new Rect (260, 20, 20, 30), "X")) {

    Mouseoperations=false;



    }
    GUI.Label(new Rect(15, 65, 50, 65),content1.tooltip);
    GUI.Label(new Rect(85, 65, 50, 65),content.tooltip);
    GUI.Label(new Rect(140,65,40,65),content2.tooltip);
    GUI.Label(new Rect(200,65,56,65),content3.tooltip);





    }

    GUI.DragWindow();

    }

    }
     
    Last edited: Sep 5, 2015