- Home /
Assign Material by script: Javascript?
I need some help in assigning material by script.
The situation is like this: I have a script attached to the camera which creates a GUI.button. The GUI.button will attach a script to the camera when the user clicks on it. The user will then be able to draw on the screen.
Here comes the problem. I have a variable for the material in the script. However, as I am only activating the script when the game is running, I am unable to assign the material through the inspector.
Is there any way to assign the Material through script?
EDIT: Solved by using Resource.Load method.
You don't mark answers as solved by writing "solved" in the title; as Orion said you add your solution as an answer and mark it as the correct answer.
Answer by Orion 1 · Nov 09, 2010 at 09:34 AM
You could make your script run in the editor (via ExecuteInEditMode).
Or you could apply the material in the function OnDrawGizmosSelected, which is regularly called when you have the object selected in the editor.
i managed to get it to work by the Resources.Load method. thanks for your help anyway
Please add your solution as an answer and mark it as the correct answer to your question. That way it will be easier for other people with the same problem to find it.
Your answer
Follow this Question
Related Questions
Cannot Assign Material To Object 1 Answer
Convert string to material 0 Answers
How to make good parser to get colours from RGBa and set them to objects 1 Answer
Random.Range doesn't work 1 Answer