Unity Quick C# Code Tips : Don't Destroy on load singleton tutorial

preview_player
Показать описание
This is just quick Unity C# code tips, don't destroy on load is a build in unity function. Radiobush has no affiliation to Unity but highly recommend Unity as a game development engine. This tutorial is for beginners and up. it might help you if don't destroy on load isn't working
Рекомендации по теме
Комментарии
Автор

Just what I needed, explained in 1 minute, thank you.

robeeer
Автор

just what i was looking for, and super fast tutorial ;D

sinho
Автор

Hi, I have 3 unity scenes, one for the Game Menu, one for the options menu when you click the options button in the Game Menu. Once this options menu loads and i change some of the options then click back and play then when the actual game plays, the options reset, the changes made in the options menu are basicaly discarded how do i stop this?

JamesBond-jpdp
Автор

Very nice video length, however for me it doesnt seem to work.
Originally I had a script that was just dont destroy on load and atached it to my music, and pause manager which worked great for when entering levels.
Problem is that when I return to the main menu my level music doesnt stop, etc. If I load in a level again I have 2 of that levels music playing symultaneously.
I dont really get why this code of yours didnt fix my second issue, instead it just made it so the music doesnt even play now, so I'm completely stumped lol
Any help is greatly appreciated!

trueblue
Автор

I have a problem here is my script I don't get what I'm doing wrong
here is my script :


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
private static GameManager instance;
// Start is called before the first frame update
void Awake()
{
if(instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;

}
}

// Update is called once per frame
void Update()
{

}
}

treeadam
Автор

OK never mind i did a genius plan by making a empty gameobject thats a parent called timer data and made it so the timers data would go to the TimerData object so when i load next scene i still Have the TimerData object

treeadam
Автор

don't mind if I steal that nice script 😜

teamofwinter
visit shbcf.ru