- Home /
How would I run functions within a script that's not attached to a gameobject?
I've made a script with some function in it though it's not attached to a gameobject. I have another script that is attached to a gameobject that i want it to run a function from the non-attached script though I don't have a idea on how to do this.
I have tried but it seems to keep giving me errors
Any help?
Answer by Vagonn · Jan 28, 2016 at 06:07 AM
[EDIT] non-attached script must not inherited from MonoBehaviour. Then you can declare this script on attached script
public class nonAttachedScript
{
-- your code --
}
Then
public class attachedScript : MonoBehaviour
{
nonAttachedScript nas = new nonAttachedScript ();
}
also take note that you will need to use a constructors ins$$anonymous$$d of Awake and Start and that you need to instantiate it with the new keyword
When you use a class without monoBehavior, it will work and be used just like a normal class in visual studio
If is just a function you can try use the static
keyword.
Your answer
