728x90

Invoke

Invoke 함수를 사용하면 메서드가 나중에 호출되도록 예약할 수 있습니다. 이 영상에서는 Unity 스크립트에서 Invoke, InvokeRepeating, CancelInvoke 등의 함수를 사용하는 방법을 알아봅니다.

InvokeScript

using UnityEngine;
using System.Collections;

public class InvokeScript : MonoBehaviour
{
    public GamaObject target;

    private void State()
    {
        Inboke(nameof(SpawnObject),2);
    }

    private SpawnObject()
    {
        Instantiate(target, new Vector3(0,2,0),Quaternion.identity);
    }
}

InvokeRepeating

using UnityEngine;
using System.Collections;

public class InvokeRepeating : MonoBehaviour 
{
    public GameObject target;


    void Start()
    {
        InvokeRepeating("SpawnObject", 2, 1);
    }

    void SpawnObject()
    {
        float x = Random.Range(-2.0f, 2.0f);
        float z = Random.Range(-2.0f, 2.0f);
        Instantiate(target, new Vector3(x, 2, z), Quaternion.identity);
    }
}

참고 : 유니티 튜토리얼

728x90

'게임엔진 > Unity' 카테고리의 다른 글

Unity - 인스턴스화  (0) 2024.07.02
Unity - Class  (0) 2024.07.02
Unity - 데이터 유형  (0) 2024.07.02
Unity - GetComponent  (0) 2024.07.02
Unity - OnMouseDown  (0) 2024.07.02

+ Recent posts