Hello guys,
I’m using one class that manages all animations events of my game.
But I would like it to have only one instance (Singleton).
The problem is that I need to attach it to the objects where I need an interaction during the animation, and its here on my problem comes up. When I set the Singleton pattern, it removes the other GameObjects that also use that same class.
Is there any solution for this? Or am I thinking the hard way?
public class MonoBehaviourSingletonPersistent<T> : MonoBehaviour
where T : Component
{
public static T Instance { get; private set; }
public virtual void Awake ()
{
if (Instance == null) {
Instance = this as T;
DontDestroyOnLoad (this);
} else {
Destroy (gameObject);
}
}
}
Any help is welcome!
Cheers.