
Invoke
Tutorial
Beginner
+10XP
5 mins
(35)
Unity Technologies

Invoke 함수를 사용하면 메서드가 나중에 호출되도록 예약할 수 있습니다. 이 영상에서는 Unity 스크립트에서 Invoke, InvokeRepeating, CancelInvoke 등의 함수를 사용하는 방법을 알아봅니다.
이 튜토리얼은 스크립팅의 기초 프로젝트에 포함되어 있습니다.
이전: 배열
다음: 열거형
1. Invoke
InvokeScript
using UnityEngine;
using System.Collections;
public class InvokeScript : MonoBehaviour
{
public GameObject target;
void Start()
{
Invoke ("SpawnObject", 2);
}
void 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);
}
}