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 Christopher Travis · Apr 14, 2011 at 08:40 PM · animationguitriggerguitext

How do i make a text box appear on screen after a chest has been opened?

Hi, ive made a chest animation triggered when a player reaches the chest that it opens up, i now want to make it so once this animation is triggered a text box will appear saying what you received out of the chest.

How do i go about doing this?

This is the script i already have in place incase it is needed.

  function OnTriggerEnter (Player : Collider) 
  {  
    animation.Play("Take 001");
  }

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 Danilo Nishimura · Apr 14, 2011 at 10:13 PM

Hi,

If you want to draw something on GUI, you can use the OnGUI method for GUI drawing.

see if this sample helps (someone help to port it to JS for him?) :

bool displayMessage = false;

void OnTriggerEnter ( Collider Player ) { animation.Play("Take 001"); }

void OnGUI ( ) { if ( displayMessage ) { GUI.Label(new Rect(Screen.width 0.5f - 50f, Screen.height 0.5f - 10f, 100f, 20f), "Testing"); } }

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 Justin Warner · Apr 14, 2011 at 10:16 PM 0
Share

This'd be perfect... Better than $$anonymous$$e. 1 problem, display$$anonymous$$essage never becomes true... So in the OnTriggerEnter, make it true, then put in the yield, and make it false again after a certain amount of time. Nice Danilo!

avatar image Danilo Nishimura · Apr 14, 2011 at 10:18 PM 0
Share

You have to set display$$anonymous$$essage = true on the OnTriggerEnter method. I forgot that =/

avatar image Christopher Travis · Apr 14, 2011 at 10:29 PM 0
Share

Can i use this as a boo script or should i try n keep all my scripts in java? thanks for the help guys

avatar image Danilo Nishimura · Apr 15, 2011 at 02:04 PM 0
Share

I think the result is the same as it's compiled to an intermediate language before the final compilation. I recommend you to write all your scripts in the same language to maintain a coding pattern and you won't get confused about which language to use when writing new files. Even if you get a sample code from somewhere, I recommend to rewrite it.

avatar image
-1

Answer by Christopher Travis · Apr 15, 2011 at 12:38 AM

I had the problem i mentioned in the comments above with the code you supplied, so i made a few alterations so there were no errors and i could get in play mode, but now the text just appears from the start and doesnt dissapear rather than appearing when the animation is triggered.

heres the new code ive had to use so it said there were no errors. changes i had to make were,

function OnTriggerEnter (Player : Collider) {
                to
function OnTriggerEnter (Player : Collider) 

it didnt like the extra { at the end because it wasnt attached to anything, when i tried just adding another one of them at the end it caused more errors. ALSO

if ( displayMessage )
       to
if ( "displayMessage" ) 

im guessing these changes are the reason it doesnt appear at the right time but it was the only way to remove the errors. Is there any help you can give to correct this so it appears at the right time when the animation is triggered?

Thanks

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 Justin Warner · Apr 15, 2011 at 01:35 AM 0
Share

$$anonymous$$y bad with the bracket, however display$$anonymous$$essage is actually a String you're to initialize before you actually run the function. And what's wrong now? Does it not work?

avatar image
0

Answer by Justin Warner · Apr 14, 2011 at 10:15 PM

Make this a seperate script on the same object...

function OnGUI () {
    GUI.Label (Rect (10, 10, 100, 20), "You picked up a pick ax!");
}

Then....

function OnTriggerEnter (Player : Collider) { animation.Play("Take 001"); GetComponent(SHOWMESSAGE).enable = true; yield WaitForSeconds(3); GetComponent(SHOWMESSAGE).enable = false;

}

Check out how to use GetComponent: http://unity3d.com/support/documentation/ScriptReference/Component.GetComponent.html

Good luck!

TO _ JAVA

displayMessage = false;

function OnTriggerEnter (Player : Collider) { { animation.Play("Take 001"); displayMessage = true; yield WaitForSeconds(3); displayMessage = false; }

function OnGUI ( ) { if ( displayMessage ) { GUI.Label(new Rect(Screen.width /2, Screen.height / 2, 200, 200), "Testing"); } }

Ignore mine, use his, but this can work I think... Not the best when not on my computer.

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 Christopher Travis · Apr 14, 2011 at 11:32 PM 0
Share

thanks for that conversion. ive copied over the code, but it is co$$anonymous$$g up with this problem,

Assets/NewBehaviourScript.js(5,43): BCE0044: expecting :, found ';'.

i dont know how to solve this one, should one of the lines have a colon ins$$anonymous$$d of semicolon?

avatar image Christopher Travis · Apr 15, 2011 at 12:31 AM 0
Share

ive posted sumthin i hope u can help with as an answer below so its easier to see

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

HELP with scripting where GUI is involved 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Sliding door animation question. 3 Answers

How to trigger animations in a script using character controller ? 0 Answers

GUIText after animation 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