当类继承与MonoBehaviour时
public class TestSingle : MonoBehaviour
{
public static TestSingle Instance;
void Awake()
{
Instance = this ;
}
}
当类不继承与MonoBehaviour时
public class TestSingle :
{
public static TestSingle instance;
public static TestSingle Instance
{
get
{
if(instance == null)
instance = new TestSingle();
return instance;
}
}
}