Invoke
확인 완료한 버전: 4.2
-
난이도: 초급
The Invoke functions allow you to schedule method calls to occur at a later time. In this video you will learn how to use the Invoke, InvokeRepeating, and CancelInvoke functions in your Unity scripts.


Invoke
초급 Scripting
InvokeScript
Code snippet
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);
}
}
#pragma strict
var target : GameObject;
function Start()
{
Invoke ("SpawnObject", 2);
}
function SpawnObject()
{
Instantiate(target, new Vector3(0, 2, 0), Quaternion.identity);
}
import UnityEngine
import System.Collections
public class InvokeScript(MonoBehaviour):
public target as GameObject
private def Start():
Invoke('SpawnObject', 2)
private def SpawnObject():
Instantiate(target, Vector3(0, 2, 0), Quaternion.identity)
InvokeRepeating
Code snippet
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);
}
}
#pragma strict
var target : GameObject;
function Start()
{
InvokeRepeating("SpawnObject", 2, 1);
}
function SpawnObject()
{
var x : float = Random.Range(-2.0f, 2.0f);
var z : float = Random.Range(-2.0f, 2.0f);
Instantiate(target, new Vector3(x, 2, z), Quaternion.identity);
}
import UnityEngine
import System.Collections
public class InvokeRepeating(MonoBehaviour):
public target as GameObject
private def Start():
InvokeRepeating('SpawnObject', 2, 1)
private def SpawnObject():
x as single = Random.Range(-2.0F, 2.0F)
z as single = Random.Range(-2.0F, 2.0F)
Instantiate(target, Vector3(x, 2, z), Quaternion.identity)