1. GameObject.Find()
- 오브젝트의 이름을 통해서 오브젝트에 접근 후 오브젝트 안에 있는 클래스에 접근
- 오브젝트의 이름이 변경 될 경우 오류남
- 비활성 오브젝트는 접근 불가 ㅜㅜ 실행 순서 생각하면서 써라..
- 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 = GameObject.Find("Controler").GetComponent<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;
void Start()
{
state = State.Go;
Debug.Log($"start State: {state}");
}
public void Control( )
{
state = State.Stop;
Debug.Log($"Con State: {state}");
}
}
'게임 클라이언트 프로그래밍' 카테고리의 다른 글
게임 오브젝트인 스크립트 컴포넌트의 매서드 실행하기 (0) | 2024.08.22 |
---|---|
게임 오브젝트에 연결된 클래스에 접근 하는 방법: Inspector 직접 연결 / 접근_한정자 게임오브젝트_타입 변수명; (0) | 2024.08.21 |
게임 오브젝트에 연결된 클래스에 접근 하는 방법: FindObjectOfType<T>(); (0) | 2024.08.21 |
Vector(x,y,z) (1) | 2024.08.20 |
라이프 사이클 = 이벤트 함수 실행 순서 (1) | 2024.08.19 |