How can a popup window appear and disappear while the user touches another object
Dear unity specialists,
I have a question regarding the popup window. My popup window should not be visible by default. It should appear after a part of a 3D object has been touched. Since I am new in Unity/Vuforia/Scripting, I tried to watch tutorials, look for scripting examples, search in the forum. The pieces of code I could find unfortunately do not work for my project. A short description of my project: I have an image target which calls up my 3D object (works). I already have implemented raycasting and colliders for the parts of the 3d object (works at least while clicking on them, don't know if it works while touching on them on the touch screen, probably LeanTouch could help here). Now I want a text box or a popup window appear as a reaction on touching these colliders. I tried to implement it with SetActive (true and false) but since I do not have any experience, I always get a lot of scripting errors. I do not think it is something that cannot be realized with Unity and Vuforia.
So if somebody has time and idea how can it be implemented / how the script should look like, I would be very glad to read and try out your answers. Thank you very much for your help!
Answer by LiloE · Mar 06, 2017 at 07:34 AM
There's a good example in the docs:
https://docs.unity3d.com/ScriptReference/GUILayout.Window.html
You can add an if
statement around it so it will only show when a certain boolean is true, and set that boolean when the user clicks a relevant object.
Example
Rect windowRect = new Rect(50, 50, 200, 100);
bool showWindow = false;
void OnGUI() {
if (GUILayout.Button("Give me popup!")) {
showWindow = true;
}
if (showWindow) {
windowRect = GUILayout.Window(0, windowRect, WindowProc, "Lilo Window");
}
}
void WindowProc(int windowID) {
GUILayout.Label("This is a pop up window");
if (GUILayout.Button("Click to close Lilo Window")) {
showWindow = false;
}
}
Answer by ptachaneu · Mar 06, 2017 at 10:29 AM
Thank you, sounds good! Could you please write a code example? Thanks!
I've added an example. Please remember to accept the answer (green check mark) if you find it helpful.
Thank you, LiloE! I tried it out. The popup appears after clicking the button. Great!
In my project,it is not the button that initiate the popup, it is a part of a 3d model. How can I rewrite the script according to this requirement? I am not sure, what category does the part of the 3d model belong to. GameObject? How can I address it in a correct way: private GameObject part3D; if part3D clicked showWindow = true;
Sorry, I am very new here...
Your answer
Follow this Question
Related Questions
How do you make a script to close out this pop up menu? 1 Answer
Hold to peek or peek and pop in android 0 Answers
Inspector popup list for custom enum-like class 0 Answers
How to unlock screen after UI popup? 0 Answers
Saving an image's state 2 Answers