MonoBehaviour.CancelInvoke
Deklarasyon
public void CancelInvoke();
Açıklama
Bu MonoBehaviour üzerindeki tüm Invoke çağrılarını iptal eder.
using UnityEngine; using System.Collections.Generic; public class ExampleScript : MonoBehaviour { public GameObject projectile; void Start() { // 2 saniye içinde başlıyor, her 0.3 saniyede bir mermi fırlatılacak InvokeRepeating("LaunchProjectile", 2.0f, 0.3f); } void LaunchProjectile() { // Bir mermi oluştur ve hızını rastgele bir yöne ayarla GameObject instance = Instantiate(projectile); Rigidbody rigidbody = instance.GetComponent(); rigidbody.velocity = Random.insideUnitSphere * 5; } void Update() { // Tüm Invoke çağrılarını iptal et if (Input.GetButton("Fire1")) CancelInvoke(); } }
Deklarasyon
public void CancelInvoke(string methodName);
Açıklama
Bu davranış üzerindeki methodName adlı tüm Invoke çağrılarını iptal eder.
using UnityEngine; using System.Collections.Generic; public class ExampleScript : MonoBehaviour { public GameObject projectile; void Start() { // 2 saniye içinde başlıyor, her 0.3 saniyede bir mermi fırlatılacak InvokeRepeating("LaunchProjectile", 2.0f, 0.3F); } void LaunchProjectile() { // Bir mermi oluştur ve hızını rastgele bir yöne ayarla GameObject instance = Instantiate(projectile); Rigidbody rigidbody = instance.GetComponent(); rigidbody.velocity = Random.insideUnitSphere * 5; } void Update() { // Sadece LaunchProjectile invoke'unu iptal et if (Input.GetButton("Fire1")) CancelInvoke("LaunchProjectile"); } }
Bu blog Unity Docs'un Türkçeye çevrilmiş halidir.
Yorumlar
Yorum Gönder