x


Open GUI.window when a 3d object is clicked

Hi all, I would open a GUI.window when a 3d object on the scene is clicked ...something like this: http://answers.unity3d.com/questions/8144/trying-to-pick-up-and-see-paper-pop-up-gui-window-to-examine-objects-when-click

...but for open a window not a texture (because I want to drag it and control the alpha amount)

This is my GUI.window code:

var windowOpen : boolean = true;
var windowRect : Rect = Rect (20, 20, 450, 450);
var customSkin : GUISkin;
var aTexture : Texture;
var button : int;

function OnGUI () {
  GUI.skin = customSkin;
  GUI.color.a = 0.8;
  if (windowOpen) {
    windowRect = GUI.Window (5, windowRect, WindowFunction, "My Window");
  }
}

function WindowFunction (windowID : int) {
  // Button to close the window here
  if (GUI.Button (Rect (0, 0,30, 30), "X")) {
    windowOpen = false;    
  }
  GUI.DrawTexture(Rect(0,0,400,400), aTexture, ScaleMode.ScaleToFit, false, 0f);
  GUI.DragWindow (Rect (0,0,430,430));
}

any suggestions? thanks. bye.

more ▼

asked Feb 22 '11 at 03:15 PM

luciano gravatar image

luciano
11 2 2 3

Did you read the answer to the question you linked to? Duck explains how to use OnMouseDown and OnMouseUp to make things happen when an object is clicked on. All you'd have to do is make them toggle windowOpen.

Feb 22 '11 at 04:11 PM burnumd

Exactly what burnumd said..

Feb 22 '11 at 04:18 PM Joshua

Idiotto........

Feb 22 '11 at 05:00 PM pauldstewart
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

sorry for stupid question ...I'm a newbie ... pauldstewart: "idiotto?" ... do you want to offend me? ..why? btw I have solved with these scripts:

//ClosePainting (GUI.texture script)

var windowOpen : boolean;
var windowRect : Rect = Rect (20, 20, 450, 450);
var customSkin : GUISkin;
var aTexture : Texture;
var button : int;

// hide the window
function Start() {
    Hide(); 
}

// if I click the 3D object on the scene, the variable is true and...
 function Show(painting : Painting) {
  windowOpen = true;    
}

// ... set the custom skin, alpha, window rect and start WindowFunction
 function OnGUI () {
  GUI.skin = customSkin;
  GUI.color.a = 0.8;
  if (windowOpen) {
    windowRect = GUI.Window (5, windowRect, WindowFunction, "My Window");
  }
 }

// create a X button for close the window and drag the window with texture
function WindowFunction (windowID : int) {
    if (GUI.Button (Rect (0, 0,30, 30), "X")) {
    Hide();    
  }
  GUI.DrawTexture(Rect(0,0,400,400), aTexture, ScaleMode.ScaleToFit, false, 0f);
  GUI.DragWindow (Rect (0,0,430,430));
}

// hide function for close the window (boolean=false)
function Hide() {
    windowOpen = false; 
} 

and 3D object script:

function Update () {
}

private var closePainting : ClosePainting;

function Start () {
    closePainting = FindObjectOfType(ClosePainting);
}

function OnMouseDown () {
    closePainting.Show(this);
}

now I'm working on rotate and zoom the window and cursor change (from arrow to hand)..

more ▼

answered Feb 23 '11 at 01:24 PM

luciano gravatar image

luciano
11 2 2 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2209
x120
x55

asked: Feb 22 '11 at 03:15 PM

Seen: 1876 times

Last Updated: Feb 22 '11 at 03:15 PM