- Home /
Changing a second objects material on trigger
Hi, I am new to Unity and C# (Have experience in C and Java) and I'm trying to create a trigger that makes a block semi-transparent.
This code segment is meant to make 'obj' change material to assigned (transparent) material mat:
public class RoofTriggerHome : MonoBehaviour {
public GameObject obj;
private Renderer rend;
public Material mat;
void start()
{
rend = obj.GetComponent<Renderer>();
}
void OnTriggerEnter(Collider node)
{
rend.material = mat;
}
}
And here is my trigger object:
The trigger works and has the ability to destroy the object if the destroy function is used. The material does not change. I have googled the hell out of this problem and none of the fixes worked.
Thanks, Neil
start() should be uppercase void Start()
, rend is never initialised so OnTriggerEnter should throw you a NullReferenceException.
Haha this was literally my issue! It has now been solved! Thank you!
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Change 'Color Mask' Property At Runtime 1 Answer
Changing two different objects renderer colour 1 Answer
Change material color at runtime!! 5 Answers
How do i change default material ? 1 Answer