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}");
    }
}

 

+ Recent posts