Require Component
Tue Oct 03, 2017 6:40 pm
Sometimes in script you require the object to have a certain component. This may be a rigidbody, text, box collider. Anything at all.
Sometimes when you try and use a component which isnt there a lot of errors/bugs and crashes can occur, which we all know is very frustrating.
Using the “RequireComponent” means you cant delete the component while this script is attached. Its awesome!
For example; Say we are manipulating the Text element of the UI.
At the top of the script. After the using and before the class we type
“ [RequireComponent(typeof(Text))] “
Like this.
This will now mean we cant remove the component in the inspector.
Like this.
Sometimes when you try and use a component which isnt there a lot of errors/bugs and crashes can occur, which we all know is very frustrating.
Using the “RequireComponent” means you cant delete the component while this script is attached. Its awesome!
For example; Say we are manipulating the Text element of the UI.
At the top of the script. After the using and before the class we type
“ [RequireComponent(typeof(Text))] “
Like this.
This will now mean we cant remove the component in the inspector.
Like this.
Permissions in this forum:
You cannot reply to topics in this forum
|
|