- Home /
Question by
WMS · Sep 10, 2012 at 11:18 AM ·
triggermesh rendererappear
Simple appear trigger not working for me
Alright, I want to do the simple solution to make a weapon that is parented to my camera appear when I walk into a trigger.
I unchecked Mesh Renderer to make my weapon invisible.
I made an empty game object. I added a box collider and I checked the box to make it a trigger.
I made a prefab for my weapon. The weapon is called "bow".
I tried to make a script with the Mesh Renderer in mind. I put the script on the trigger.
This is the script:
var bow : MeshRenderer;
function OnTriggerEnter() {
bow.MeshRenderer.enabled = true;
}
I dragged the bow prefab into the slot the script has for "bow".
"I keep getting: Object reference not set to an instance of an object."
I know I am missing something, but I don't know what it is.
Comment
Best Answer
Answer by svenskefan · Sep 10, 2012 at 01:53 PM
Hi! Since bow is already of type MeshRenderer, you should write;
var bow : MeshRenderer;
function OnTriggerEnter() {
bow.enabled = true;
}