---
title: "延时调用方法"
author: "whuthj"
date: "2011-05-11T18:40:53Z"
tags: []
categories: ["互联网"]
slug: "untitled"
draft: false
lastmod: "2011-05-11T18:40:53Z"
id: 1040387
url: "https://whuthj.iteye.com/blog/1040387"
---

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