How to activate a component from its reference?
Hi, I have a script, which has a public Component variable named t.
public Component t;
I want to set that component to be active from code, in runtime. How do I do it?
Thanks!
Answer by jebemti · Feb 26, 2016 at 01:31 PM
Use this if you want to enable a script:
public MonoBehaviour component;
Scripts derive from MonoBehaviour which has the 'enabled' variable defined.
Some components however don't inherit from MonoBehaviour. For example Rigidbody inherits from behaviour.
For these components you need to do something specific to disable.
Answer by phil_me_up · Feb 26, 2016 at 01:27 PM
t.enabled = true; will enable it.
Best to have a look at this tutorial to understand the basics: https://unity3d.com/learn/tutorials/modules/beginner/scripting/enabling-disabling-components
I am not a new user btw. I have tried doing that ,obviously,and It doesn't work.
Like the property .enabled doesn't exist.
Your answer
![](https://koobas.hobune.stream/wayback/20220612065714im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to load a GameObject from Byte[] in the scene on runtime? 2 Answers
GameObject clone name not updating on editor 0 Answers
Change Material of an GameObject at Runtime using a bitmap dynamically created 1 Answer
Set object reference for script at runtime 0 Answers
How can I change the design of game_object at runtime? 0 Answers