Question by
DroidifyDevs · Feb 04, 2016 at 05:27 PM ·
c#scripting problemgameobjectsetactiveother-object
How to enable script on another gameobject in C#?
Hello!
I've made many scripts, but this has me stumped. I need to make a button on my canvas that when clicked, will enable a script on another gameobject. So here's what I need:
public void EnableOtherScript()
{
othercomponent.gameObject.SetActive(true)
}
However I don't know how to make the othercomponent since it is a script on another gameobject.
Thanks for the help :)
Comment
Answer by Jessespike · Feb 04, 2016 at 09:22 PM
public MonoBehaviour othercomponent;
public void EnableOtherScript()
{
othercomponent.enabled = true;
}
Drag and drop the GameObject that has the script you want enabled to othercomponent in the Inspector.