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 lehart · Jan 06, 2014 at 07:04 PM · javascriptcolorchange3d text

3D Text - How to change colour - Doesn't seem to work

Okay so my script is below, and if I view it on my font materials the colour changes, however it doesn't change when on the actual game view? - very odd, anyone got any input on how I can fix this? - I'm doing a very basic Main Menu.

 var isQuit=false;
 
 function OnMouseEnter(){
 //change text color
 renderer.material.color = Color.red;
 }
 
 function OnMouseExit(){
 //change text color
 renderer.material.color = Color.black;
 }
 
 function OnMouseUp(){
 //is this quit
 if (isQuit==true) {
 //quit the game
 Application.Quit();
 }
 else {
 //load level
 Application.LoadLevel("level1");
 }
 }
 
 function Update(){
 //quit game if escape key is pressed
 if (Input.GetKey(KeyCode.Escape)) { Application.Quit();
 }
 }
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

Answer by edcarlo · Jan 07, 2014 at 06:21 AM

 // try this
 gameObject.GetComponent<TextMesh>().color = Color.red;
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 lehart · Jan 07, 2014 at 09:49 AM 0
Share

Thanks for the reply, tried that but getting the following error. "Assets/Scripts/javascript/mainmenu.js(5,35): BCE0043: Unexpected token: )."

avatar image Nagare_Hoshi · Mar 22, 2015 at 04:38 PM 0
Share

I know I might be late, but in case anyone has the problem with an unexpected token error, try to use gameObject.GetComponent(Text$$anonymous$$esh).color = Color.red; At least this works in unity 5.

avatar image
0

Answer by Brood · Jan 07, 2014 at 11:00 AM

I am assuming that, in the game view, when you hover the mouse over the 3D text (hence OnMouseEnter), you want it to change to red, and when you leave the mouse from the 3D text (hence OnMouseExit), you want it to change it back to black.

If thats the case, changing color of the text in the game, it is possible that you didn't add a collider to the 3D text. A collider is absolutely necessary for the OnMouseEnter/OnMouseExit to function, as it allows detection of the mouse.

Solution:

Select the 3D text, then go to its inspector.

Add Component - Physics - Box Collider

Select the Box Collider, and you should see a green wireframe on the scene view.

Adjust the collider to fit the text.

If successful, the 3D text should recognise the mouse and should be able to change color.

This is my best suggestion that I can provide, and it's possible that this isn't what you are looking for. If so, sorry about that. My only favor from you is to be specific with your question, as I can also assume that you want to see the change of your font material color in game.

Good day.

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 lehart · Jan 07, 2014 at 11:25 AM 0
Share

Thanks for the reply. Yes you are correct in assu$$anonymous$$g that I wish to see a change in font colour in game.

I've added a box Collider to both my 3D Text objects but it's still not changing, if I look in the Text $$anonymous$$aterial view I can see it changes colour there, but in game view it doesn't.

I know the box collider works because my On$$anonymous$$ouseUp command works for both pieces of text.

avatar image lehart · Jan 07, 2014 at 11:38 AM 0
Share

I've deleted my old 3D text objects and started them from fresh, the script I used first now seems to work, looks like I might have changed something without realising. All is good now, how do I close this question?

avatar image Brood · Jan 07, 2014 at 12:01 PM 0
Share

From what I researched, the most I found out it you need 1k points of karma to be able to close a comment. Bet you can get that piece-of-cake?

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

20 People are following this question.

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

Related Questions

Switching color of light 1 Answer

Why does my 3d text keep turning white? 1 Answer

change a material from multiple materials 1 Answer

change skybox via script help ? 1 Answer

Change colour of int when reaches specific number 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