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
1
Question by Raymond 2 · Mar 14, 2011 at 08:22 PM · guitriggershowin

on collision show gui

i got this script that should take you to another level when all of the objects are collected when entering this trigger, but i want it to show a text in screen when you didn't collect all the objects, anyone who can help??

Here's the current script:

// Get script from another object var itemTracker; itemTracker = GameObject.FindWithTag("GameController").GetComponent(GameStats);

// Number of the next level (can be found under File/Build Settings) var nextLevel = 3;

// If a collider is hit and all the objects are lower than 1 (0) then load the next leven function OnTriggerEnter (other : Collider) { if(itemTracker.wax < 1 && itemTracker.wood < 1 && itemTracker.feathers < 1) Application.LoadLevel(nextLevel); }

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 Raymond 2 · Mar 14, 2011 at 08:55 PM

I figured it out, i knew i needed a boolean but i then the message stayed there, but i got it working now, here's the final script for anybody who wants to do the same:

// Get script from another object var itemTracker; itemTracker = GameObject.FindWithTag("GameController").GetComponent(GameStats);

// Number of the next level (can be found under File/Build Settings) var nextLevel = 3;

//variable to check if all objects are collected var allCollected = false; var triggerHit = false; // If a collider is hit and all the objects are lower than 1 (0) then load the next level // When a collider is entered check if all the objects are collected and looad the next level function OnTriggerEnter (other : Collider) { triggerHit = true; if(itemTracker.wax < 1 && itemTracker.wood < 1 && itemTracker.feathers < 1) { Application.LoadLevel(nextLevel); allCollected = true; }

} // when the trigger is left, wait for 5 seconds, and set the triggerhit variable to false function OnTriggerExit (other : Collider) { yield WaitForSeconds(5); triggerHit = false; }

function OnGUI() { // if not all items are collected (allCollected = false;) and triggerhit is true then show a text in the middle of the screen wich says you have items to collect if(!allCollected && triggerHit) { GUI.Label (Rect (Screen.width/3, Screen.height/2, 600, 40), "You still have some objects to collect"); } }

EDIT: Added comments for clearity (just for those who don't understand and for documentation)

Comment
Add comment · Show 4 · 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 cregox · Mar 14, 2011 at 09:03 PM 0
Share

now you could accept your own answer! or so I hope. maybe you can only do it 2 days from now...

avatar image poncho · Mar 14, 2011 at 09:26 PM 0
Share

the bool was meant to turn on and off when you need it in this case the bool goes true in your on trigger enter on the respective else in your code and goes false on the true of that if i thought that part was common sense, still the answer works

avatar image Raymond 2 · Mar 14, 2011 at 09:28 PM 0
Share

yea i just had a brain dead moment so i didn't know what to do, i probably asked to soon, but anyway thanks for the help.

As for accepting my own answer, it takes 24 hours before i can do that.

avatar image Raymond 2 · Mar 14, 2011 at 09:28 PM 0
Share

sorry i meant 46 hours xD

avatar image
1

Answer by poncho · Mar 14, 2011 at 08:46 PM

you need first have a class boolean variable that will decide when the GUI is showed then you need to assign it true when you want to show the GUI on the OnGUI function add the if(myboolean) then yourRespectiveGUI and that was all you needed

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

Can I set a specific Pointer for the EventTrigger on Buttons for example? 0 Answers

Loading a scene in game with a GUI 1 Answer

Press button if you are inside a trigger (Sorry) 2 Answers

2 scripts 1 script sending text and 2 script receiving this text 0 Answers

Help with making a triggered gui message 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