1. FindObjectOfType<T>();
- 이름이 같아야 함
- 여러 개면 첫번째 찾은 거 참조
- 비활성 오브젝트는 접근 불가 ㅜㅜ 실행 순서 생각하면서 써라..
> 시작 시, Go 상태였다가 Con 매서드를 호출해 Stop으로 상태를 바꾼다.
- App
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;
public class App : MonoBehaviour
{
void Start()
{
Controler controler = FindObjectOfType<Controler>();
controler.Control();
}
}
- Controler
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controler : MonoBehaviour
{
private enum State
{
Go, Stop
}
private State state;
// Start is called before the first frame update
void Start()
{
state = State.Go;
Debug.Log($"start State: {state}");
}
public void Control( )
{
state = State.Stop;
Debug.Log($"Con State: {state}");
}
}
Control 매서드를 private로 선언하면 참조 불가
public enum State {...} / private State state; 는 가능
'게임 클라이언트 프로그래밍' 카테고리의 다른 글
게임 오브젝트에 연결된 클래스에 접근 하는 방법: Inspector 직접 연결 / 접근_한정자 게임오브젝트_타입 변수명; (0) | 2024.08.21 |
---|---|
게임 오브젝트에 연결된 클래스에 접근 하는 방법 GameObject.Find(); (0) | 2024.08.21 |
Vector(x,y,z) (1) | 2024.08.20 |
라이프 사이클 = 이벤트 함수 실행 순서 (1) | 2024.08.19 |
룰렛 돌리기 (0) | 2024.08.19 |