How do I create a popUp in unity3d?

I want to create a PopUp for my game, my requirement is to open the popUp when the user clicks the button. And popUp contains an image for its background, a close button in the top right corner, and two buttons on popUp (lets you say "Yes" and "No"). I am doing R&D but nothing was found. Any help would be appreciated.

PS I don't want to use third party plugins like NGUI, 2D ToolKit, etc.

+3


source to share


2 answers


Unity up to 4.5

You can build most of the components using GUITexture

the legacy UI system.

http://docs.unity3d.com/Manual/class-GuiTexture.html

Create your background and buttons from the textures below. For buttons, you can also use GUIText

and make clickable / touchable.

enter image description here

See the scripting guide for details.

http://docs.unity3d.com/Manual/GUIScriptingGuide.html



Unity 4.6 or newer

Unity's GUI system makes this easy. For the background, you will need Canvas

and Sprite

. And two buttons as children for YES and NO.

enter image description here

See the introduction first http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/the-new-ui

The manual shows all the components http://docs.unity3d.com/Manual/UISystem.html

GUI link http://docs.unity3d.com/ScriptReference/GUI.html

+3


source


Try to create something like this for the popup button (JavaScript):

var popupactive : boolean = false;
var (Name of the GUI window) : GUITexture;
var (Picture1) : GUITexture;
var (Picture2) : GUITexture;
var (Picture3) : GUITexture;
(Name off the GUI window).enabled = false;
(Picture1).enabled = false;
(Picture2).enabled = false;
(Picture3).enabled = false;   

function OnMouseUp(){
   if(popupactive==false){
       popupactive = true;
       }
       else{
       popupactive = false;
       (Name of the GUI window).enabled = false;
       }
}

      



Then try adding a function that closes the GUI for the exit button and the no button to close the open GUIs. Also, don't forget to import the individual scripts assigned to individual buttons within the code! Remember also to assign them in the Unity editor. Hope this helps!

+1


source







All Articles