인프런 커뮤니티 질문&답변

Link님의 프로필 이미지

작성한 질문수

[C#과 유니티로 만드는 MMORPG 게임 개발 시리즈] Part3: 유니티 엔진

Singleton 패턴

go = new GameObject(name = "@Managers"); 버그

23.10.16 10:46 작성

·

341

·

수정됨

0

using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;

public class Managers : MonoBehaviour
{
private static Managers s_instance;
public static Managers instance {get {init(); return s_instance; }}
// Start is called before the first frame update
void Start()
{
init();
}

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

}

static void init()
{
if (s_instance == null)
{
GameObject go = GameObject.Find("@Managers");
if (go == null)
{
go = new GameObject(name = "@Managers");
go.AddComponent<Managers>();
}
DontDestroyOnLoad(go);
s_instance = go.GetComponent<Managers>();
}
}
}

 

Managers.cs(29, 37): [CS0120] static이 아닌 필드, 메서드 또는 속성 'Object.name'에 개체 참조가 필요합니다.


이런 오류가 뜨는데 어떻게 수정해야 될까요? 제가 놓친 부분이 있을까요?

답변 1

0

Tory님의 프로필 이미지

2023. 10. 17. 10:41

(name = "@Managers") -> {name = "@Managers"} 으로 바꾸셔야 할꺼 같습니다

Link님의 프로필 이미지
Link
질문자

2023. 10. 17. 13:31

감사합니다

Link님의 프로필 이미지

작성한 질문수

질문하기