- Home /
How to setActive to change the material
I tried to gaze spheres to change a 3D plane materials as change GUI pages by use event trigger and bool enabled but when i point back to the first sphere it doesn't change anything. How to write a script to setActivate ??
https://youtu.be/8OoHxHIOL90<<<<<<<<<<<<< video
if i point a sphere,the scripts will activate.
{
public Material page_1;
void Start()
{
}
void Update()
{
GetComponent<Renderer>().material = page_1;
}
}
Answer by Mouton · Sep 25, 2019 at 01:37 PM
To change a renderer material, you need to create a new material array and update the materials
array (not material
which is just a handy acessor to change active material attributes). Here is some example code:
void SetMaterial()
{
var newMaterials = new Material[1];
newMaterials[0] = myMaterial;
GetComponent<Renderer>().materials = newMaterials;
}
If the answer statisfies you, please mark it as "answered" so that other users know your problem is resolved.
Your answer
Follow this Question
Related Questions
Steam VR : Make latency 0 Answers
Is there any way to mirror a non unity application 0 Answers
What is the Input Key for the Steam Vive triggers? 1 Answer
Is it possible to access SteamVR settings with a script? 0 Answers
AutoWalk Oculus Rift 0 Answers