- Home /
Convert string to material
Hi,
I have a string variable from another script that needs to act as the name of a predefined material that needs to be used, but Unity can't read the string as a material.
var deskObject : GameObject; var ESE : Material; var ESL : Material; var currentMat = currentMaterial.MaterialsScript; // The string from the other script returns the string "ESE" or "ESL";
function Update() { deskObject = GameObject.Find("desk_object_01"); deskObject.renderer.material = currentMat; }
How can I convert this?
Thanks!
out of scope for the question, but very important nontheless: don't use Find within the Update function, it's not efficient. ins$$anonymous$$d declare a variable to host that reference.
Hi, before I answer. Do you need it to be set only once for the whole game or can it be changed?
Your answer
![](https://koobas.hobune.stream/wayback/20220613133936im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
convert string to array to write to document 0 Answers
Convert Javascript class to a string 0 Answers
convert string to color 3 Answers
Check What Material is Being Used? 1 Answer
Convert c# to Js? 1 Answer