Legacy Documentation: Version 5.2
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

MonoBehaviour.InvokeRepeating

Switch to Manual
public void InvokeRepeating(string methodName, float time, float repeatRate);

Parameters

Description

Invokes the method methodName in time seconds, then repeatedly every repeatRate seconds.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Rigidbody projectile; void LaunchProjectile() { Rigidbody instance = Instantiate(projectile); instance.velocity = Random.insideUnitSphere * 5; } void Example() { InvokeRepeating("LaunchProjectile", 2, 0.3F); } }