I have 2 Singleton example scripts (A and B)
Is there any difference in the two?
Is one way better than the other, perfomance or otherwise?
Please explain
Singleton example A
using UnityEngine;
using System.Collections;
public class gameManager : MonoBehaviour
{
public int score;
private static gameManager mySingleton;
public gameManager Instance
{
get
{
return mySingleton;
}
}
protected void Awake ()
{
mySingleton = this;
}
public void SetScore (int i)
{
score += i;
}
}
Singleton example B
using UnityEngine;
using System.Collections;
public class gameManager : MonoBehaviour
{
public int score;
public static gameManager mySingleton;
void Awake ()
{
mySingleton = this;
}
public void SetScore (int i)
{
score += i;
}
}
Are Singletons better than SendMessage and GetComponent?
context, I have 3 Triggers, when an object Enters each Trigger 1 is added to that Trigger’s corresponding int variable in the Game Manager Script on a different object from the Triggers