I want to create a PopUp for my game, my requirement is to open a popUp when user click a button.
And popUp contains a image for its background, a close button on upper-right corner and two buttons on the popUp (lets say YES & NO).
I make R&D but nothing found relevant.
Any help would be appriciated.
P.S. I don't want to use any third party plugIn Like NGUI, 2D ToolKit etc.
Unity till 4.5
You can build most components with GUITexture wiht the legacy UI system.
http://docs.unity3d.com/Manual/class-GuiTexture.html
Build your background and buttons from textures of the scheme below. For the buttons you also use GUIText and make the clickable/touchable.
For more info see the scripting guide.
http://docs.unity3d.com/Manual/GUIScriptingGuide.html
Unity 4.6 or newer
The GUI system of Unity easily allows you to do that. You will need a Canvas and a Sprite for the background. And two buttons as children for YES and NO.
See the introduction first
http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/the-new-ui
The manual shows all components
http://docs.unity3d.com/Manual/UISystem.html
GUI Reference
http://docs.unity3d.com/ScriptReference/GUI.html
Try creating something like this for the pop-up 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 "no" button to close the opened GUIs, Also remember to import the separate scripts assigned to the separate buttons inside the code! Remember also to assign them in the Unity editor. Hope it helps!
Related
So I have been working on a pause menu for a game I have been working on with Game Maker Studio 2.
Whenever I change rooms (like going to the options room or main menu) the pause menu stays and everything looks very weird and overlapped. Is there a way to check if I have changed rooms to destroy the objects the menu is made up of
(So like if (room has changed) {Delete pause menu})*
If someone could give me the correct syntax that would be awesome!
Thanks.
*I have sorted out deleting the menu, just need to know what to put in the if statement
For my game, I've done a check if the room is the same as the room in the main menu/options menu, or make a check that the pause menu only appear when it's not the main menu/options menu.
var roomname = room_get_name(room);
if (roomname != r_mainmenu && roomname != r_optionsmenu)
{
//draw pause menu
}
Another idea is to hide the pause menu once you go back to the main menu.
So I have a pause menu created in unity. There is a panel and on it, there are three buttons but they do not seem to be working, meaning I can not click on them. Also, interactable of every button is checked and event system is present in the hierarchy.
Hierarchy image
Following is the code for the resume button:
public void resumegame()
{
levemusic.UnPause();
pausemenu.SetActive(false);
Cursor.visible = false;
gameisPaused = false;
Time.timeScale = 1;
}
Either disable this component on the panel
Or move the panel object such that it is on top of the hierarchy in the object hierarchy
I have tried to create a tab-view or tab-group like control on smartface.io but I can't find any solution on the website.
Please any one have idea on how to create tab group. I can't find any tab-view on their the view pallet of IDE. thanks
You can use textbuttons, place them at the top of the page, use as many as you need. And place container objects under these buttons. When you press a button, make the related container's visibility true and other's false. For example, when pressed button1, let
cont1.visible = true;
cont2.visible = false;
cont3.visible = false;
and so on.
Also you should check Smartface in Action project. You can find project in Welcome page, for example in pgListView.
How do I create a button that links to another scene in my main menu (and by the way it is 2d). I tried the OnGUI code, it did link it to the scene, but it just linked it to the scene straight away after pressing the play button without clicking it.
You need a texture for the button, a nice 2D sprite will do. Just load through the editor. Then you add the code above to a script. Notice that you need an if, or else bad things happen :D (I could not resist the pun).
If you want to make it so that when you hit a specific button do it like this:
var texture: Texture;
function OnGUI()
{
if(GUI.Button(Rect(10,10,50,50), texture))
Application.LoadLevel("SceneName");
}
Or If you don't want to use the default GUI style provided by Unity you can do this:
function OnGUI()
{
var r = Rect(10,10,50,50);
GUI.DrawTexture(r, texture);
if(Event.current.type == EventType.MouseUp
&& r.Contains(Event.current.mousePosition))
Application.LoadLevel("SceneName");
}
Both versions of the code allow you to click the button and do something afterwards; in this case is switch scenes.
More on GUI stuff can be found here.
I am new to createJS toolkit (Flash CS6), My concept is I have a multiple buttons on the stage, each button click will have different animations in different frames.
my code is
'/* js
this.stop();
this.btnname.onPress = function()
{ this.parent.gotoAndPlay("cone"); }
*/'
it is perfectly working in all browsers and android mobile, but in iPhone it is not working,
I am trying to click on the button but canvas is highlighting in iphone,
when I change my code to the following code,
'/* js
this.stop();
this.onPress = function()
{ this.gotoAndPlay("cone"); }
*/'
It is working in iPhone, but I have multiple button clicks, here is my major problem.
Please help me find a solution to this issue.
Use addEventListener and listen for the "click" or "mousedown" event instead of assigning an onPress function. Like this:
/* js
this.stop();
this.btnname.addEventListener("click", function(){
this.parent.gotoAndPlay("cone");
});
*/
You need to create a shape, cache it and use it as the hitArea of your button. john has answered your question here: http://community.createjs.com/discussions/easeljs/5663-touch-on-ios-only-seems-to-work-with-bitmaps