none
CS1503_引數 1: 無法從 'System.Collections.IEnumerable' 轉換成 'string'_Assembly-CSharp_ RRS feed

  • 問題

  • 我進行unity遊戲製作

    出現在StartCoroutine(PlayVideo());這行有問題

    錯誤訊息如標題:CS1503 引數 1: 無法從 'System.Collections.IEnumerable' 轉換成 'string' Assembly-CSharp 

    c#:

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

    public class VIDEO : MonoBehaviour{
        public RawImage rawImage;
        public VideoPlayer videoPlayer;
        public AudioSource audioSource;
        // Start is called before the first frame update
        void Start()
        {
            StartCoroutine(PlayVideo());
        }
        IEnumerable PlayVideo()
        {
            videoPlayer.Prepare();
            WaitForSecondsRealtime waitForSeconds = new WaitForSecondsRealtime(1);
            while (!videoPlayer.isPrepared)
            {
                yield return waitForSeconds;
                break;
            }
            rawImage.texture = videoPlayer.texture;
            videoPlayer.Play();
            audioSource.Play();
        }
    }

    想請問各位大神指點?
    • 已編輯 andylola 2019年3月27日 下午 01:37
    2019年3月27日 上午 08:10

解答

  • using UnityEngine;
    using System.Collections;
    using System;
    using System.Collections.Generic;
    using UnityEngine.UI;
    using UnityEngine.Video;
    public class VIDEO : MonoBehaviour
    {
        public RawImage rawImage;
        public VideoPlayer videoPlayer;
        public AudioSource audioSource;
        void Start()
        {
            StartCoroutine(PlayVideo());
        }

        IEnumerator PlayVideo()
        {
            videoPlayer.Prepare();
            while (!videoPlayer.isPrepared)
            {
                yield return new WaitForSecondsRealtime(5);
                break;
            }
            rawImage.texture = videoPlayer.texture;
            videoPlayer.Play();
            audioSource.Play();
        }
    }

    後來改成這樣就可以了^^

    2019年3月27日 下午 02:28