Unity 3 dでタイマーの使用


ソースhttp://wiki.ceeger.com/start?do=search&id=Invoke
  • 遅延は、一般的な機能n秒後に関数を実行し、n秒ごとに関数を繰り返し実行します.
  • は後悔しました.キャンセルしたいですか?すべてキャンセルしてもいいです.特定の遅延設定だけキャンセルしてもいいです.
  • MonoBehaviour.Invokeの呼び出しが遅れました.
    JavaScript⇒Invoke(methodName:string、time:float):void;C〓〓〓void Invoke(string methodName、float time);
    Descriptionの説明
    Invokes the method method Name in time seconds.
    time秒後に、メソッドmethodNameを呼び出します.
    JavaScript:
    // Launches a projectile in 2 seconds
    
    var projectile : Rigidbody;
    
    Invoke("LaunchProjectile", 2);
    
    function LaunchProjectile () 
    { 
        var instance : Rigidbody = Instantiate(projectile); 
        instance.velocity = Random.insideUnitSphere * 5; 
    } 
    Cシシシ:
    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() {
            Invoke("LaunchProjectile", 2);
        }
    }
    MonoBehaviour.Invoke Repeatingの繰り返し呼び出し
    JavaScript⇒InvokeRepeating(methodName:string、time:float、repeat Rate:float):void;C〓〓〓void Invoke Repeat ing(string methodName、float time、float repeate);
    Descriptionの説明
    Invokes the method method Name in time seconds,then repeated every repeat seconds.
    タイムではmethodNameメソッドを呼び出し、それからrepeat Rate秒ごとに呼び出しを繰り返します.
    JavaScript:
    // Starting in 2 seconds.
    // a projectile will be launched every 0.3 seconds
    
    var projectile : Rigidbody;
    
    InvokeRepeating("LaunchProjectile", 2, 0.3);
    
    function LaunchProjectile () 
    { 
        var instance : Rigidbody = Instantiate(projectile); 
        instance.velocity = Random.insideUnitSphere * 5; 
    } 
    Cシシシ:
    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);
        }
    }
    MonoBehaviour.Clance Invokeキャンセル遅延呼び出し
    JavaScript⇒Call Invoke():void;C葃⇒void Call Invoke();
    Descriptionの説明
    Call all Invoke calson this MonoBehaviour.
    現在のMonoBehaviourでは、すべてのInvokeコールをキャンセルします.
    JavaScript:
    // Starting in 2 seconds.
    // a projectile will be launched every 0.3 seconds
    var projectile : Rigidbody;
    InvokeRepeating("LaunchProjectile", 2, 0.3);
    
    // Cancels the repeating invoke call, 
    // when the user pressed the ctrl button 
    function Update() 
    { 
        if (Input.GetButton ("Fire1")) 
            CancelInvoke(); 
    }
    
    function LaunchProjectile () 
    { 
        instance = Instantiate(projectile); 
        instance.velocity = Random.insideUnitSphere * 5; 
    } 
    Cシシシ:
    using UnityEngine;
    using System.Collections;
    
    public class ExampleClass : MonoBehaviour {
        public Rigidbody projectile;
        void Update() {
            if (Input.GetButton("Fire1"))
                CancelInvoke();
    
        }
        void LaunchProjectile() {
            instance = Instantiate(projectile);
            instance.velocity = Random.insideUnitSphere * 5;
        }
        void Example() {
            InvokeRepeating("LaunchProjectile", 2, 0.3F);
        }
    }
    JavaScript⇒Call Invoke(methodName:string):void;C葃⇒void Call Invoke(string methodName);
    Descriptionの説明
    Call all Invoke call with name methodName on this behaviour.
    現在のbehaviourでは、すべての方法をmethodNameというInvoke呼び出しをキャンセルします.
    JavaScript:
    // Starting in 2 seconds.
    // a projectile will be launched every 0.3 seconds
    
    var projectile : Rigidbody; 
    InvokeRepeating("LaunchProjectile", 2, 0.3);
    
    // Cancels the repeating invoke call, // when the user pressed the ctrl button 
    function Update() 
    { 
        if (Input.GetButton ("Fire1")) 
            CancelInvoke("LaunchProjectile"); 
    }
    
    function LaunchProjectile () 
    { 
        instance = Instantiate(projectile); 
        instance.velocity = Random.insideUnitSphere * 5; 
    } 
    Cシシシ:
    using UnityEngine;
    using System.Collections;
    
    public class ExampleClass : MonoBehaviour {
        public Rigidbody projectile;
        void Update() {
            if (Input.GetButton("Fire1"))
                CancelInvoke("LaunchProjectile");
    
        }
        void LaunchProjectile() {
            instance = Instantiate(projectile);
            instance.velocity = Random.insideUnitSphere * 5;
        }
        void Example() {
            InvokeRepeating("LaunchProjectile", 2, 0.3F);
        }
    }