I have three of classes that I am using in my game and I got curious about Singleton pattern.
I have used singleton to access variables or functions easier and I didn't know how to access it without using a singleton pattern only except making "public GameObject" variable and assign object that has a script that I need in inspector.
under here is my sample code
public class ExampleClass : MonoBehaviour
{
public static ExampleClass instance;
private void Awake()
{
instance = this;
}
}
public GameObject assignScriptObject;
as you see, in the ExampleClass I used singleton pattern that I made and at the las line is how I will assign script in inspector.
Is it fine to use Singleton pattern (I call functions a lot by using that instance) {i.e. ExampleClass.instance.LoadSomeFunctions() } there are dozens of lines with other functions
OR
Is it better to assign script in inspector as an aspect of optimization.
THANKS!