Trick or True
[Unity]InvokeRepeating 본문
MonoBehaviour.InvokeRepeating:
Invokes the method methodName in time seconds, then repeatedly every repeatRate seconds.
To cancel InvokeRepeating use MonoBehaviour.CancelInvoke.
Note :The time and repeatRate parameters depend on Time.timeScale. For example, if Time.timeScale is 0 InvokeRepeating will not invoke. On the other hand, if Time.timeScale is 2, InvokeRepeating will repeat twice as fast.
InvokeRepeating은 메서드를 호출해 반복하는 메서드이다.
InvokeRepeating(string methodName, float time, float repeatRate)
- methodName: 반복 실행할 메소드 이름
- time: 첫 실행까지 대기 시간 (second)
- repeatRate: 반복할 간격 (second)
private float startDeley = 2;
private float spawnInterval = 1.5f;
void Start()
{
//SpawnRandomAnimal()을 게임 시작 후 2초 후에 첫 실행하고, 이후 1.5초마다 반복 실행한다.
InvokeRepeating("SpawnRandomAnimal", startDeley, spawnInterval);
}
MonoBehaviour를 상속받은 클래스에서만 사용 가능하며, CancelInvoke()로 반복을 중지할 수 있다.
'게임 개발' 카테고리의 다른 글
| [Unity] projection(투영) (0) | 2024.11.08 |
|---|---|
| [Unity] Instantiate() 함수 (0) | 2024.11.07 |
Comments