Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by rustystar · Oct 20, 2010 at 09:06 AM · guimenugroup

Create a sliding Menu

Hi all, I am just learning Unity 3 and I am finding the learning curve quite steep for me.

At this point of time, I've managed to do up a decent GUI interface with GUIskin and GUI Group. If let's say I would like to make the whole GUI group slide out of the menu upon keypress(spacebar), which command should I be using? Am I doing it right in the first place because I can't seem to get the whole GUI Group to move on keypress.

Below is my code:

@script ExecuteInEditMode()

//This command is to run your GUI scripts without having to play the scene

//variable for GUISkin var customSkin : GUISkin;

var icon : Texture;

var plate : Texture;

//Slider default values when you first run Unity. var slider = 50;

//var windowRect : Rect = Rect (20, 20, 120, 50);

function OnGUI () {

//applies skin to all. any GUI elements above this script will not get "skinned". GUI.skin = customSkin;

//Everything in a group will move accordingly is you adjust the x and y values. GUI.BeginGroup (Rect (Screen.width/2-480,Screen.height/2-240, 960,480 ));

// We'll make a box so you can see where the group is on-screen. //GUI.Box (Rect (0,0,960,480), "Interface Group 1");

GUI.Label (Rect ( 0, 0, 960, 480), plate);

//To set the button to load levels, add your scenes from the Build Settings. if (GUI.Button (Rect (60,25,80,30), "Level 1")) { Application.LoadLevel (1); }

GUI.Button (Rect (280,25,80,30), "Button 2");

GUI.Button (Rect (500,25,80,30), icon);

GUI.Label (Rect (760, 135, 128,128),icon);

// End the group we started above. GUI.EndGroup ();

}

//////What command should I use here for the keypress function?/////////////

function Update () { if (Input.GetKeyDown (KeyCode.Space)){

print ("space key was pressed");

//(command to use here?);

}

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by rustystar · Oct 27, 2010 at 08:08 AM

I've already managed to add the function in by using variables assigned to the x coordinates and rewriting the whole structure.

Many thanks to HiggyB!

Below are the working scripts: @script ExecuteInEditMode()

var MyBoxLeft = -200.0;

var icon : Texture; var icon2 : Texture; var blankSkin : GUISkin;

function OnGUI () { GUI.skin = blankSkin; var tBoxRect = new Rect(MyBoxLeft, 20.0, 220, 720); var tButtonRect = new Rect(MyBoxLeft, 160.0, 120, 30); var tBoxArt = new Rect(MyBoxLeft, 200.0, 120, 120);

GUI.Box(tBoxRect, icon); GUI.Button(tButtonRect, "Click"); GUI.Box(tBoxArt, icon2); }

function Update () {

if (Input.GetKeyDown("space")) { AnimateBox(); }

}

function AnimateBox () {

if (MyBoxLeft == -200.0) {

while (MyBoxLeft < 20.0) {
    MyBoxLeft+=5.0;
    yield;
}

} else if (MyBoxLeft == 20.0) {

while (MyBoxLeft > -200.0) {
    MyBoxLeft-=5.0;
    yield;
}

}

}

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image thesfid · Dec 11, 2012 at 06:00 PM 0
Share

This is great. Thanks for sharing :)

avatar image muralinath · Jun 18, 2014 at 05:11 AM 0
Share

How to change the button click ins$$anonymous$$d of space

avatar image
0

Answer by pagan · Jun 15, 2011 at 01:39 PM

What if I want to modify this script so that the box opens when clickin on it? Thanks

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How do I make a stylish GUI? 0 Answers

NGUI: Recommended way of hiding/showing multiple menu panels? 1 Answer

Non rectangular GUI Mask / Matte? 2 Answers

Another GUI question. enable and disable 1 Answer

How to place/add a HD image/picture in background of my game? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges