Adding a singleton script to 2 objects makes one of them dissapear.
I have added this code :
public class Singleton : MonoBehaviour
{
public static Singleton inst;
// Start is called before the first frame update
private void Awake()
{
if (Singleton.inst == null)
{
Singleton.inst = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
}
I have tried to have other classes and scripts inherit from Singleton in order to apply the dontdestroyonload to the object they are attached to. But the same error happens. I m using singleton to keep the player, and the inventory with all the items.
I don't understand what do you want destroy everything or keep everything ?
If you want to keep all objects just delete destroy
If you want to delete all objects delete Singleton
If you want for Singleton to only 1 exist keep the code as it's working.
Your answer
Follow this Question
Related Questions
How to make a Inventory Hotbar 0 Answers
Launchers for Players 1 Answer
Top Down Character - Face direction of movement? 0 Answers
Problem with prefab 0 Answers
[Problem] Unity crashes when trying to build or preview on Android 0 Answers