- Home /
Changing the colour of a 3DText through script gives a weird error
SCREENSHOTS GOT MESSED UP, CANT EMBED AND THEY'RE IN THE WRONG ORDER.
I want to change the colour of 3D text through a script, and the first time you use it, it works perfectly fine. No problem there. But the first time the text pops up, the 'Element 0' changes to 'Type mismatch', and then when you stop the game, it turns into screenshot 2.
Then the next time you start the game, the text will turn into screenshot 1.
Then you have to keep on reassigning the font material in the inspector every single time you want to start the game again. I am using a custom font, and this is my code for changing the colour: goldMesh.renderer.material.color = Color.yellow; which works perfectly fine before it spazzes out.
(edit: okay, the screenshots wont appear correctly for some reason, so just click on attachments)
Did you select the font in the "Text $$anonymous$$esh" component (last entry)? When you select a proper font you should not have to bother with the material settings in the "$$anonymous$$esh Renderer".
Does changing the color work when you change the font import settings?
What version are you using? 4.0? Pro?
Sometimes a simple restart of the editor (especially on windows) does help with some weird errors.
I can change the font color with your code line fine, several times, no issues here. (Unity 4.0.0f7 Pro)
Yeah, when I put the font onto it, I didn't need to change anything else. It worked perfectly. It's just the script that's messing it up, it seems to remove it from the component or something.
I don't know what you mean about the import settings. What could I change?
I'm using 4.0.0f7 Normal version.
I restarted. Still being weird.
I also totally forgot to mention that it comes with this error whilst the text popups weirdly: 'Shader wants normals, but the mesh doesn't have them'
When you select the font in your project you can change the input settings, like "Font Color". If changing it there works, it's probably not a font issue.
Perhaps you can post the script, the one line you did post works fine.
Also, you can try everything in a new project, add a font, add a 3DText, finally add your script. $$anonymous$$ight help narrowing down the error.
Check here for the same error.
Your answer
Follow this Question
Related Questions
Generated meshes/materials cannot be made into prefabs? 1 Answer
HDRP shader graph - Surface options missing "Material Type" in inspector 0 Answers
Is it possible to create a Material _asset_ from a script? 3 Answers
Assigning meshes & materials from Assets, how? 1 Answer
How do I add a tool tip for class variables in the inspector? 1 Answer