DontDestroyOnLoad() 가 적용이 안됩니다
1022
작성한 질문수 5
코드는 제대로 작성했는데 정작 유니티로 돌아가면 적용되지 않는 이유가 무엇일까요.........


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Managers : MonoBehaviour
{
static Managers s_instance; //유일성 보장
public static Managers Instance { get { init(); return s_instance; } } //유일한 매니저를 가져온다
// Start is called before the first frame update
void Start() //반드시 부품으로 들어가있을때만 호출 가능함 (즉 monobehaviour이 필요함)
{
//초기화
//Instance = this;
init();
}
// Update is called once per frame
void Update()
{
}
static void init()
{
if (s_instance == null)
{
GameObject go = GameObject.Find("@Managers");
if (go == null) //@manangers가 없다면
{
go = new GameObject { name = "@Managers" };
go.AddComponent<Managers>();
}
DontDestroyOnLoad(go); //웬만해서는 삭제 안됨
s_instance = go.GetComponent<Managers>();
}
}
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Managers mg = Managers.Instance;
}
// Update is called once per frame
void Update()
{
}
}
답변 1
0
유니티로 돌아가서 [실행]을 해야지 @Managers가 만들어지는 것입니다.
그런데 이미 @Managers를 수정으로 배치해 놓으셔서,
이 코드가 스킵이 될 것으로 예상됩니다.
매니저 관련 질문이 있습니다.
0
28
2
비쥬얼 스튜디오에서 unity연결이 없습니다.
0
50
2
UI 기능 관련 질문이 있습니다!
0
50
2
픽셀 좌표 스크린 좌표
0
35
0
전체적으로 코드 읽는게 굉장히 오래 걸리네요...
0
86
2
카메라 #2 수업 캐릭터 쓰러짐 해결
0
89
1
플레이어 움직임이 끝날때, 기울어짐 현상
0
87
1
Input 적용과 관련하여 질문 있습니다.
0
78
1
디버그 불가.. Unity에 연결 불가
0
85
1
달리기 애니메이션 에러
0
95
2
오랜만에 게임을 만들다가 사운드 관련해서 뭔가 궁금한게 있어서 봤습니다
0
68
1
GetKey 오류
0
115
2
에셋을 어디에 올려두신지 알 수 있나요?
0
111
1
재귀호출? 오류나는데 왜 이래요 ?
0
171
6
Animation blending 파라미터 계산
0
71
1
newPos와 to지점이 겹쳐져야 하는거 아닌가요?
0
100
3
오브젝트 복제하니까 자꾸 이런게 뜨면서 꺼집니다
0
89
2
질문있습니다
0
145
2
아 이거 소스코드 같은거 없나요?
0
145
3
질문 드립니다. string.IsNullOrEmpty(name)
0
90
2
@Managers 가 씬에 배치되어 있어도 문제가 되지 않나요?
0
137
2
유니티6 NavMesh 안되는분들
1
178
1
Unity6 Unity-Chan Material 마젠타 문제 해결법
7
540
1
GetComponent<Poolable> 질문드립니다.
0
104
2





