简体   繁体   中英

Unity Click and Pass WaitForSeconds

I'm making simple 2d game. This is opening scene. (Logos images showing).I want to if mouse click down (0) Time passes and other image show. How can i do it?

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class OpeningCanvasScript : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(otherImage());
        
    }
    private void Deactivate()
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            transform.GetChild(i).gameObject.SetActive(false);
        }
    }
    private IEnumerator otherImage()
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            Deactivate();
            transform.GetChild(i).gameObject.SetActive(true);
            yield return new WaitForSeconds(3f);
            // I want to if mouse click down (0) Time passes and other image show
        }
        SceneManager.LoadScene(2);
    }
}```

I think i did it this way

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class OpeningCanvasScript : MonoBehaviour
{
    bool finished = false;
    void Start()
    {
        StartCoroutine(otherImage());
        
    }
    private void Deactivate()
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            transform.GetChild(i).gameObject.SetActive(false);
        }
    }
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            finished = true;
        }
    }
    private IEnumerator otherImage()
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            finished = false;
            Deactivate();
            transform.GetChild(i).gameObject.SetActive(true);
            StartCoroutine(waitSeconds());
            yield return new WaitUntil(()=>finished);

        }
        SceneManager.LoadScene(2);
    }
    private IEnumerator waitSeconds()
    {
        yield return new WaitForSeconds(3f);
        finished = true;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM