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 BraveVN · Apr 12, 2014 at 03:57 AM · textmesh3dtext

I cannot change 3D Text (Text Mesh) color

Like the title, In my game, I make a 3D Text that display every time I hit the button, and each time it has a random color. I create an array to store the color

 private Color[] textColor = {Color.black, Color.blue, Color.cyan, Color.gray, Color.green, Color.grey, Color.magenta, Color.red, Color.white, Color.yellow};

Then I used this code, when the game's played, I look into the Inspector window and font material has changed exactly what I need but the color of the 3D text on the screen only changed into 3 types: Red (default color of text), Black, Brown. How can I fix it ?

 void Start(){
       // some stuffs
       textLR = transform.GetComponent<TextMesh>();
 }
 
 void Update(){
       // some stuffs
       index = Random.Range (0, textColor.Length);
 }
 
 void OnGUI(){
       // some stuffs
       transform.GetComponent<MeshRenderer>().material.SetColor("_Color", textColor[index]);
 }
Comment
Add comment · Show 3
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 BraveVN · Apr 12, 2014 at 01:22 PM 0
Share

please help me

avatar image Gruffy · Apr 12, 2014 at 02:15 PM 0
Share

Hey BraveVN, I answered this the other day for someone else on here, below is the link and please use the search functionality of the site , it may turn up more than you expect.

Heres the link

AnsweredTheOtherDay

Cheers bud Gruffy Edit: btw, read the whole thing, at the bottom of answer there is a zip file to download if you find following the resolution difficult or anything.

avatar image BraveVN · Apr 14, 2014 at 12:28 AM 0
Share

thank you, I'll try this and come here to response later, it look hard for me :)

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by akauper · Apr 14, 2014 at 12:51 AM

Your using a TextMesh, correct?

Will this work for you?

 private Color[] textColor = new Color[9]{Color.black, Color.blue, Color.cyan, Color.gray, Color.green, Color.grey, Color.magenta, Color.red, Color.white, Color.yellow};
 
 void Start(){
       textLR = transform.GetComponent<TextMesh>();
 }
  
 void Update(){
 
       index = Random.Range (0, textColor.Length);
 }
  
 void OnGUI()
 {
       textLR.color = textColor[index];
 }

Am I misunderstanding something? There is no need to access the material. TextMesh has a built in 'color' property which is public get and set

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 BraveVN · Apr 15, 2014 at 12:13 AM 0
Share

thank you, it's worked

avatar image
1

Answer by importsjc · Apr 12, 2014 at 02:41 PM

This is C# i assume, Im a Js guy but i got it working in both. the only things i changed to your code was making a variable called index and commenting out the textLR line and it works just fine. this is code i put in a C# script called "Test2" on the 3d text:

 using UnityEngine;
 using System.Collections;
 
 public class Test2 : MonoBehaviour {
     private Color[] textColor = {Color.black, Color.blue, Color.cyan, Color.gray, Color.green, Color.grey, Color.magenta, Color.red, Color.white, Color.yellow};
     private int index;
     void Start(){
         // some stuffs
         //textLR = transform.GetComponent<TextMesh>();
     }
     
     void Update(){
         // some stuffs
         index = Random.Range (0, textColor.Length);
     }
     
     void OnGUI(){
         // some stuffs
         transform.GetComponent<MeshRenderer>().material.SetColor("_Color", textColor[index]);
     }
 }

and this is the java script code if you want it:

 var textColor = [Color.black, Color.blue, Color.cyan, Color.gray, Color.green, Color.grey, Color.magenta, Color.red, Color.white, Color.yellow];
 var index : int;
 
 function Start () {
 
 }
 
 function Update ()
 {
     index = Random.Range (0, textColor.Length);
     transform.GetComponent(MeshRenderer).material.SetColor("_Color", textColor[index]);
 }

Hope this Helps!

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 BraveVN · Apr 14, 2014 at 12:27 AM 0
Share

Thanks for your help, but it's not work, just red (default color), brown and black :(

avatar image importsjc · Apr 14, 2014 at 10:58 AM 1
Share

Just tested the code, it seems to work fine for me. Try making a new project, then GameObject>create other>3D Text, create a new javascript and call it "Test", paste this code into the test script:

 var textColor = [Color.black, Color.blue, Color.cyan, Color.gray, Color.green, Color.grey, Color.magenta, Color.red, Color.white, Color.yellow];
 var index : int;
  
 function Start () {
  
 }
  
 function Update ()
 {
     index = Random.Range (0, textColor.Length);
     transform.GetComponent($$anonymous$$eshRenderer).material.SetColor("_Color", textColor[index]);
 }

and finally attach the script to your 3d text object. i did this and it works perfectly. Good Luck!

avatar image BraveVN · Apr 15, 2014 at 12:13 AM 0
Share

It's worked, thanks, may be the error is in another places of my project

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

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

Related Questions

How to draw 3D text from code 4 Answers

Insert 3d text to the front face of a cube GameObject 0 Answers

int to string problem 4 Answers

3D Text font issue 2 Answers

Cannot get 3D Text/Text Mesh to wrap or a attached collider used as a button to scale based on word count. 2 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