- Home /
How to make a prefab active and non-active using script?
Hi. So I I have been so much trouble with this and it is making an prefab or object visible or not visible. I have tried using " GetComponent.enabled = true/false" But its not working. I bet I have to add a component of some kind, obviously, but what kind. If there is no component what other script is there. By the way I am using Unity 5. Thank you in advance!
Answer by GeorgeIng · May 27, 2015 at 09:16 AM
It depends what you want. If you just want to disable the objects visuals then you can do: transform.renderer.enabled = false; or transform.renderer.enabled = true;
If you want to disable the whole object - including stopping Update calls etc, then you can do: gameObject.SetActive( true ); or gameObject.SetActive( false );
In most cases I find myself using the latter.