【问题标题】:How do you hide a UI object (Video Player) after time (Unity)时间后如何隐藏 UI 对象(视频播放器)(Unity)
【发布时间】:2019-05-04 18:27:10
【问题描述】:

我对使用 Unity 非常陌生,而且我靠 YouTube 上的教程过活。我的游戏一启动,就会使用视频播放器开始播放视频。我希望在视频播放完毕后隐藏视频以显示我的菜单屏幕。我确实有一个用来隐藏视频播放器的脚本

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

public class HideVideo : MonoBehaviour
{

public GameObject VideoPlayer;
public void HideVideoPlayer()
{
    VideoPlayer.gameObject.SetActive(false);
}
}

问题是,我最接近实际隐藏视频的方法是通过按钮将其设置为 onclick 事件。视频播放完毕后如何让视频播放器隐藏?谢谢。

【问题讨论】:

  • 你试过VideoPlayer.isPlaying 吗?如果你没有循环播放视频,你可以使用这个或者你可以使用VideoPlayer.loopPointReached

标签: c# unity3d video-player


【解决方案1】:

当它停止播放并将其放入更新时,为什么不简单地隐藏它?

void Update() {
    if (!(VideoPlayer.isPlaying)) {
        VideoPlayer.gameObject.SetActive(false);
    }
}

一个完整的脚本可能如下所示:

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

public class HideVideo : MonoBehaviour
{
    public GameObject VideoPlayer;
    public bool isPlayerStarted = false;

    void Update() {
        if (isPlayerStarted == false && VideoPlayer.IsPlaying == true) {
            // When the player is started, set this information
            isPlayerStarted = true;
        }
        if (isPlayerStarted == true && VideoPlayer.isPlaying == false ) {
            // Wehen the player stopped playing, hide it
            VideoPlayer.gameObject.SetActive(false);
        }
    }   
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    • 2019-03-27
    相关资源
    最近更新 更多