纳金网

标题: Unity3d 程序定时器 [打印本页]

作者: yeu1233    时间: 2012-8-29 10:15
标题: Unity3d 程序定时器
Unity3d 固定一段时间进入某个方法

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 () {  
   if (Input.GetButton ("Fire")) {  
    CancelInvoke();  
   }  
}  
void LaunchProjectile () {  
   print("hello");  
}  
}  





欢迎光临 纳金网 (http://course.narkii.com/club/) Powered by Discuz! X2.5