I’m using below code to make my gameobject invisible at the start of my game.
foreach (Renderer ren in r)
{
ren.enabled=false;
}
then i use the below to make is visible and play the animation.
foreach (Renderer ren in r) {
ren.enabled=true;
}
both of this works.
But once the animation starts playing I want to make the object invisible at mouse clicks. I wrote below code.
void OnMouseDown(){
foreach (Renderer ren in r) {
ren.enabled=false;
}
}
But it doesn’t work.
Please tell me what am i doing wrong.Thanks.
You will need a collider on any object you want to register with OnMouseDown().
@Foulcloud
Thanks for your reply.
I did add collider to my object. In fact while debugging i tried to print a number each time the object is being clicked. Even that works.
But the object is not getting invisible with “ren.enabled=false”.
Though it works while it is not animating.
Is there something else i need to use, to make it invisible while its animating
Add Input Mouse condition in Update() :
if(Input.GetMouseButtonDown (0))
{
foreach (Renderer ren in r) { ren.enabled=false; } }
}
This may help you. Thanks.