Running a Script non attached

Hello guys,

I want to know if I can run a Script if not attached to an object.

I need handle some events and I need a script for that. But I don’t want to attach it to an object because I just want to process things…

Thanks.

Make the methods and fields in that script static.

Yes you can. For me i create a new class not inherited from anything. In the scene i have another script which calls the script. Say in the scene i have a component B and in the project i have A. So in B i will just use A like
var something : A; or in
c#

A something;

And since it doesn’t inherit from monobehavior, i can have a constructor function. But i think you can inherit from monobehaviour but you cannot have the constructors.

And to use it just call

something.DoSomethingElse(); // Instancing a class and using it instead of using static var

Depends on what you need to do, i wouldn’t say always use static variable. Since static only have 1 instance. So use it wisely.

Thanks,

I’m going to use all static because they are all game handler settings.

But talking about settings, there is another way to save system settings?

Using PlayerPrefs to save the setting or if you wan more complex saving function
user C# .net way to save
you can go to scripting reference to see how PlayerPrefs works