Yamaneko
9
Q:

singleton unity

public class Example
{
public static Example Instance{get; private set;}

void awake()
{
if(Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
} else
{
Destroy(gameObject);
}
}

}
6
#region Singleton

void Awake()
{
	if (instance == null)
	{
		instance = this;
	}
	else
	{
		Destroy(gameObject);
		return;
	}

	DontDestroyOnLoad(gameObject);
}

#endregion
3
public class Example
{
public static Example Instance{get; private set;}

void Awake()
{
if(Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
} else
{
Destroy(gameObject);
}
}

}
1

New to Communities?

Join the community