- Home /
Material Change Color on trigger.
Hello, so I have very little experience in programming. I mostly do 3D modeling. Basically I want the material to change colors when my player enters a trigger. I have a computer that I want to be dim unless the character is by the computer. Right now the computer always has the bright material.
Answer by KittenSnipes · Sep 02, 2018 at 09:49 AM
Something like this should work. I recommend checking the Unity documentation for questions like this. If you look under material or Renderer I am pretty sure you can find some great information. Otherwise here is a script that should work:
public Material brightMaterial;
public Material dimMaterial;
void OnTriggerEnter(Collider col) {
if (col.gameObject.tag == “Player”) {
transform.GetComponent<Renderer>().material = brightMaterial;
}
}
void OnTriggerExit(Collider col) {
if (col.gameObject.tag == “Player”) {
transform.GetComponent<Renderer>().material = dimMaterial;
}
}
plus 1 for checking the Unity documentation - and he also made a double post.
Your answer
Follow this Question
Related Questions
Copy collider material on trigger 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to get trigger input on an Xbox controller (Mac) 0 Answers
Accessing component of a single prefabs' instance. 0 Answers