how can i lock an Gameobject by script ?

the gamobject should be Disappear from scene when you play the game
i used render component for hidden object but it’s not hide from mouse events

sample.GetComponent<Renderer>().enabled=false;

1 Answer

1

I sort of understand what you’re getting at, but in the future please format your question in a way everyone reading can understand. “Lock” really doesn’t pertain to this situation.

To completely disable a GameObject:
Click Here For GameObject.SetActive Documentation

If you still need the object to remain active, you can use your current method plus switching layers.
Click here for Layers Documentation

its still black

–