ドキュメント

Unity Engine

Unity Engine

InvokeRepeating(string, float, float)

Invokes the specified method after a specified delay, then repeatedly at the specified rate.
読み終わるまでの所要時間 1 分最終更新 1ヶ月前

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public void InvokeRepeating(string methodName, float time, float repeatRate)

Parameters

methodName

The name of a method to invoke.

time

Time to wait in seconds before the first invocation.

repeatRate

Interval in seconds between method invocations.

Remarks

To cancel
InvokeRepeating
, use MonoBehaviour.CancelInvoke().
The
time
and
repeatRate
parameters depend on Time.timeScale. For example, a Time.timeScale of 2 effectively halves the real-time values of
time
and
repeatRate
, while a Time.timeScale of 0.5 doubles them. If Time.timeScale is 0, then the
method
is never invoked.
You can't change the value of the
repeatRate
interval while
InvokeRepeating
is running. You must cancel and re-invoke to change it.

Examples

using UnityEngine;using System.Collections.Generic;// After an initial 2 second wait, launch a projectile every 0.3 secondspublic class ExampleScript : MonoBehaviour{ public Rigidbody projectile; void Start() { InvokeRepeating(nameof(LaunchProjectile), 2.0f, 0.3f); } void LaunchProjectile() { Rigidbody instance = Instantiate(projectile); instance.velocity = Random.insideUnitSphere * 5; }}