InvokeRepeating重复定时器

JS

// Starting in 2 seconds.
// a projectile will be launched every 0.3 seconds
var projectile : Rigidbody;
InvokeRepeating("LaunchProjectile", 2, 0.3);
function LaunchProjectile () {
instance = Instantiate(prefab);
instance.velocity = Random.insideUnitSphere * 5;
}

 

C#

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start () {
   InvokeRepeating("LaunchProjectile", 1,5);//1秒后调用LaunchProjectile () 函数,之后每5秒调用一次
}

// Update is called once per frame
void Update () {

}
void LaunchProjectile () {
   print("hello");
}
}

你可能感兴趣的:(InvokeRepeating重复定时器)