Project
Beginner Gameplay Scripting
Invoke
Tutorial
Beginner
5 Mins
Unity Technologies
Overview
You have completed 0% of this Tutorial.
1.
Invoke
Summary
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.
Language
English
Recommended Unity Versions
4
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); } }

Woohoo! You nailed this tutorial.
Continue rocking your Beginner Gameplay Scripting project.
Next Step:
Enumerations
Tutorial
Beginner
5 Mins
Unity Technologies