InvokeRepeating重复定时器

来源:互联网 发布:淘宝电商运营必备表格 编辑:程序博客网 时间:2024/04/29 08:05

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

0 0
原创粉丝点击