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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by ztriv · Apr 09, 2012 at 09:10 PM · gui-text

How Can I Make it Where Text Shows and the Game Ends on Collision?

The code I have is:

 function OnTriggerEnter (other:Collider){
     guiText.text = "You Win!";
     print("You win!");
     Application.Quit();
     }

Oh and by the way, the text is attached to the object and the GUILayer is enabled. But the text does not show up, and the game does not end. The debug "You win!" I just put in to make sure it wasn't a collision problem which it is not. If anyone happens to have an idea as to what it is that I'm having issues with, I would greatly appreciate some help in resolving it. Thanks in advance.

Comment
Add comment · Show 2
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 kolban · Apr 09, 2012 at 11:39 PM 0
Share

In what environment are you running the code? In the Unity editor perhaps? It also strikes me that if you are saying that the text should change and then immediately "Quit" the game ... perhaps the logic to show the changed text is skipped as you immediately quit the game?

avatar image ztriv · Apr 10, 2012 at 11:08 PM 0
Share

I don't know what you mean by environment, I attached this code to the object to be collided with. I figured out a different way to achieve this, but the "Application.Quit()" I'm still not sure is working. Do I have to put guiText.text in a OnGUI function is that why it didn't work this way?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by by0log1c · Apr 09, 2012 at 11:43 PM

The Unity Editor will not close on Application.Quit(). Built project will.

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
avatar image
0

Answer by ztriv · Apr 10, 2012 at 11:16 PM

I meant to put this in my previous post, but the Tab button doesn't work and I didn't know it.

 var a = false;
 
 function OnTriggerEnter (other : Collider) {
     print ("Testing collision");
     a = true;
         Application.Quit();
 
 }
 
 function OnGUI(){
     if (a == true){
         GUI.Label(Rect(Screen.width/2,Screen.height/2,600,60),"You win!");
     }
 }
 
 function Update () {
 
 }
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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Material doesn't have a color property '_Color' 4 Answers

Fatal Error When I Load Unity 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