Use Invoke code to achieve 321 reciprocal

Unity uses Invoke code to realize 321 reciprocal


Invoke(“aaa”, 2); //call the function "aaa" every 2 seconds

Sample code:

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);
    }
}

Note:

Here it is called in the form of a string, if there is an error in the called function, it will not work normally

When using the UI type, the code needs to have the words using UnityEngine.UI

Example is a number, if the countdown is an image then use:

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

Guess you like

Origin blog.csdn.net/xichi_12396/article/details/116026522