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 Heratitan · Jul 13, 2010 at 09:14 PM · collisiontexttouchguitextdisplay

Displaying Text On touch

Hey, In my game I have traps that are basically just boxes and I am trying to figure out how to display GUI text when my player touches it. At the moment I have this:

var endMessage : GUIText;

function OnCollisionEnter (col : Collision) { endMessage.text = "On No... You Died, Try Again"; Application.LoadLevel(1); }

And I can't seem to fix it... If anyone has a working script on a tip that would be great. Thanks

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
0
Best Answer

Answer by lhk · Jul 13, 2010 at 09:36 PM

I'm not using Javascript but I've done something similar in c#. Create a GameObject and add a GUIText to it. Then write a script like this. Note that the c# code is just a "short version"

public static bool on; // switch the messages on and off public static string text; //text to be displayed GUIText messages // this will hold the GUIText component, to access its text

void Start() { messages=(GUIText)GetComponent("GUIText"); } void Update() { if(on) { messages.enabled=true; messages.text=text; } else { messages.enabled=false; } }

Now you can access the GUI messages by adjusting the static variables of your script. Let's assume you named your script "texthints". Then the following should work:

void OnCollisionEnter (Collision col) 
{
    texthints.text = "On No... You Died, Try Again";
    texthints.on=true
    Application.LoadLevel(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 BruteAsura · Apr 15, 2020 at 12:40 AM 0
Share

Hey I did it but it gives me error, is there any simple way? Please reply

avatar image
1

Answer by Tetrad · Jul 13, 2010 at 09:30 PM

Well assuming everything's set up right, and you are hitting the trigger, you're probably not giving it enough time to display the message before loading a level.

Try putting a yield; between the endMessage.text and the Application.LoadLevel. Try putting some text on the GUIText by default to see if it actually shows up on screen. Here are some other debugging tips.

Without knowing how your scene, GUIText, trigger, etc. are set up it's hard to know why it isn't working.

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

what is the correct way to display text on screen 1 Answer

How to display text using javascript ? 1 Answer

Problem Displaying Score on GUI text 0 Answers

How to display EULA from Doc in Unity? 0 Answers

text display on touch 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