Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by CalledToGaming · Mar 17, 2010 at 05:38 AM · guigui-button

Situational GUI popup question.

I'm having trouble with a situational GUI popup. For example, when the game loads for the first time, I want to have a GUI pop up that starts the story out. You know, tells you what's going on... story stuff. I've gotten the popup to work how I want, but I need it to only pop up the first time the level loads, not when I go back to it later or anything like that.

I tried a simple script starting out with something like

   if(Application.LoadLevel("Level 1"))
    {
    //GUI Button script here
    }

But that just gives me errors.

I've also tried something like

function OnTriggerEnter (other : Collider) { if(other.tag=="Player"){ //GUI Script Here } }

function OnTriggerExit (other : Collider) { if(other.tag=="Player"){ Destroy(this); } }

But again, I just get errors. The second seems like the more likely aproach, I just don't know what to do for the script.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Lipis · Mar 17, 2010 at 12:53 PM

You are probably getting these errors because you are trying to create GUI Controls not inside the OnGUI() function.

From GUI Basics:

UnityGUI controls make use of a special function called OnGUI(). The OnGUI() function gets called every frame as long as the containing script is enabled - just like the Update() function.

If you want to show something in the beginning of each level you can raise a flag whenever this script is started and if the flag is up display the start up message. After a while (or by clicking a button) the flag will be set to false and this message won't be displayed anymore, since we are not going to set the flag to true.

Attach this script to an object, to see an example:

var skin: GUISkin; var showIntro: boolean;

function Start() { showIntro = true; }

function OnGUI() { if (showIntro) { GUI.skin = skin; GUILayout.BeginArea(Rect(128, 128, 256, 256)); GUILayout.Box("Welcome"); GUILayout.Label("Hello, world!"); if (GUILayout.Button("Ok ok.. let me play!")) { showIntro = false; } GUILayout.EndArea(); } }

You can also create a new GUI Skin (Assets->Create->GUI Skin) and attach it to this script, in order to change the feel & like of your GUI.

If you want to show a message whenever you are clicking on an GameObject, then try doing a similar trick, but this time by enabling your flag in OnMouseDown() function.

Comment
Add comment · Show 3 · 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 CalledToGaming · Mar 17, 2010 at 06:46 PM 0
Share

Cool, thanks. Now lets take the second case farther. Lets say for example I want a GUIbox with text to pop up when a player enters a certain area, or even better when they click on a specific object (like a note on a table) and I want it to pop up the GUI box. How do I go about doing that? I think I'm on the right track, but i'm not sure.

avatar image CalledToGaming · Mar 17, 2010 at 06:48 PM 0
Share

Or is there a script function that I can use that will call on another script (like a GUI script) and activate it when a certain action has been preformed?

avatar image Lipis · Mar 17, 2010 at 07:45 PM 0
Share

I updated my answer.. I think I know why were getting these errors.. as for how to show some GUI controls from another script.. I think you have to ask another questions.. it's not a forum like site, so one question per question is better :)

avatar image
0

Answer by lowbloodsugar · Mar 17, 2010 at 06:51 AM

Try moving the intro video into its own level. When you build the game add that level as level 0. And posting the game as level 1.

At the end of the intro video on level 0, load level 1. Then when you want to restart the game, load level 1.

Comment
Add comment · Show 1 · 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 CalledToGaming · Mar 17, 2010 at 06:59 AM 0
Share

Right, I got that to work, the only issue is i'm making a system that requires you to reload past levels (Like loading from a cave to the world in Oblivion) and so I don't want this to pop up when I reload the world again from somewhere totally unrelated to the begining scene. $$anonymous$$ake sense?

That's why I think If i could get the second script to work it'd work better, i could spawn the guy in the trigger, and then when he leaves it, it'll just destroy it.

avatar image
0

Answer by Extrakun · Mar 17, 2010 at 09:45 AM

You need something that is called a finite state machine.

The simple way to do it is to have a variable to holds the state

var GUIState:int = 0;

function OnGUI() { switch (GUIState) { // game begins case 0: // ...GUI Script for game begins... break;

  // tutorial
  case 1:
     //....
     break;


} }

This, of course, will get tiring over time. So what you can do is to declare a class, called GUIState, has a base function called Display. Have new states to derive from the base class, overrides its update and add in the GUI code to display what you want there. But for a simple game, a simple switch-case would do.

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

No one has followed this question yet.

Related Questions

Setting Scroll View Width GUILayout 1 Answer

How to change a GUI button texture through scripting 1 Answer

How can I set up a series of OnGUI Toggle buttons in a for loop? 1 Answer

GUI button off centre 1 Answer

GUI problem 1 Answer


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