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");
}
}

posted @ 2013-09-05 16:30  马语者  阅读(11286)  评论(0编辑  收藏  举报