要在Unity WebGL项目中播放视频,你需要使用HTML5标签,需要点击不同按钮播放不同的对应视频的代码
时间: 2024-03-06 19:46:54 浏览: 78
是的,正确的做法是在Unity WebGL项目中使用HTML5标签来播放视频。你可以在HTML文件中添加一个video标签,然后使用JavaScript来控制它的播放。
以下是一个示例代码片段,可以在不同按钮被点击时播放对应的视频:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Video Player</title>
</head>
<body>
<video id="my-video" width="640" height="360" controls>
<source id="video-source" src="" type="video/mp4">
</video>
<button onclick="playVideo('video1.mp4')">Play Video 1</button>
<button onclick="playVideo('video2.mp4')">Play Video 2</button>
<script>
var videoPlayer = document.getElementById('my-video');
var videoSource = document.getElementById('video-source');
function playVideo(videoUrl) {
videoSource.src = videoUrl;
videoPlayer.load();
videoPlayer.play();
}
</script>
</body>
</html>
```
这个示例代码中,我们使用了一个video标签来显示视频,给它一个id为“my-video”,并添加了一个source标签,用于指定视频的URL和类型。然后我们添加了两个按钮,每个按钮都调用了一个JavaScript函数,当按钮被点击时,这个函数会将对应的视频URL传递给videoSource,然后调用load()和play()方法来加载和播放视频。
阅读全文
相关推荐



















