呼び出しコードを使用して 321 の逆数を達成します

Unity は Invoke コードを使用して 321 の逆数を実現します


Invoke(“aaa”, 2); // 2秒ごとに関数「aaa」を呼び出します

サンプルコード:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIScripts : MonoBehaviour
{
    
    

    public Text three;
    public Text two;
    public Text one;
    // Start is called before the first frame update
    void Start()
    {
    
    
        three.gameObject.SetActive(false);
        two.gameObject.SetActive(false);
        one.gameObject.SetActive(false);
        OnThree();
        Invoke("OnTwo", 1);
        Invoke("OnOne", 2);
        Invoke("OnEnd", 3);
    }

    public void OnThree()
    {
    
    
        three.gameObject.SetActive(true);
    }

    public void OnTwo()
    {
    
    
        Destroy(three.gameObject);
        two.gameObject.SetActive(true);
    }

    public void OnOne()
    {
    
    
        one.gameObject.SetActive(true);
        Destroy(two.gameObject);
    }
    public void OnEnd()
    {
    
    
        Destroy(one.gameObject);
    }
}

ノート:

ここでは文字列形式で呼び出しているため、呼び出された関数にエラーがあると正常に動作しません

UI タイプを使用する場合、コードにはUnityEngine.UI を使用する単語が必要です。

例は数値です。カウントダウンが画像の場合は次を使用します。

	Public Image three;
	Public Image two;
	Public Image one;

おすすめ

転載: blog.csdn.net/xichi_12396/article/details/116026522