“MovieTexture”类型或命名空间无法找到。您是否缺少使用指令或程序集引用?

3
在执行我的应用程序时,我遇到了错误(CS0246)的问题,当我尝试在Unity上使用WebGL构建我的游戏时。以下是代码:
using UnityEngine;

using System.Collections;

using UnityEngine.UI;



[RequireComponent (typeof(AudioSource))]

public class videoplayer : MonoBehaviour {

private MovieTexture movie;

private AudioSource audio;


    void Start () {

        GetComponent<RawImage>().texture = movie as MovieTexture;
        audio = GetComponent<AudioSource>();
        audio.clip = movie.audioClip;
        movie.Play ();
        audio.Play();


    }


    void Update () {

    }
}

你把光标放在 MovieTexture 上,然后按下 ctrl .,再检查一下是否有使用语句? - Grizzly
我做了这个,调试显示如下:"字段 'videoplayer.movie' 从未被赋值,因此始终具有其默认值 null"。 - Vicente Ferreira
我做了这个,调试显示2。你是什么意思?你是指Intellisense吗?你看到了哪些Using语句? - Grizzly
哦,抱歉。我只看到了纹理。 - Vicente Ferreira
1个回答

0

好的,我明白问题了。基本上,movie 被声明但没有被赋值。这就是为什么它是 null。
我认为你错过了使用此处纹理属性的对象的名称。

GetComponent<RawImage>().texture = movie as MovieTexture;.

应该像这样:

GetComponent<RawImage>()."对象名称".texture = movie as MovieTexture;


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接