inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

Singleton 패턴

cs0122, cs0120 계속 두개가 괴롭힙니다..

1857

김진호
0

player.cs

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()

{

}

}

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 

managers.cs

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Managers : MonoBehaviour

{

static Managers s_Instance; //유일성이 보장된다

public Managers instance { get { Init(); return s_Instance; } } // 유일한 매니저를 갖고온다

// Start is called before the first frame update

void Start()

{

}

// 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>();

}

}

}

 

 

도대체 어디가 문제인지 모르겠습니다 보호 수준가지고 왜 자꾸 오류가나는지

C# unity

답변 1

0

Rookiss

빌드 에러가 나는 것인가요? 보호 수준은 public 관련 문제 같은데 에러 메시지 스샷 하나를 찍어주시기 바랍니다.

0

김진호

managers instance 앞에 public static에서 static 을 뺴서 그런것 같네요 해결했습니다 감사합니다

공부 방향성

0

195

1

Desktop용 게임 개발에도 도움이 될까요?

0

202

1

진로가 큰 걱정입니다...

0

298

1

신입 게임 클라이언트 포트폴리오 레포 평가 부탁드립니다

0

294

0

개발자 자리와 AI?

0

456

1

파이어 베이스만 사용하는데

0

338

1

강의 예제 파일을 첨부해 주세요!

0

354

0

강의를 들을 때 해당 메서드의 개념이나 어떻게 작동하는지 모르고 따라 칠때가 있습니다.

0

439

0

클라이언트 네트워크 부분 수업 질문

0

340

0

강의에 대해 질문있습니다

0

417

0

객체지향을 어디서 배워야 할까요

0

378

1

메모리 누수에 대해서 질문드립니다.

1

389

3