VideoPlayer.started
Параметры
| Параметр | Описание |
|---|---|
| значение | Экземпляр VideoPlayer, который вызывает событие. |
Описание
VideoPlayer отправляет это событие, когда видео начинает воспроизводиться.
После того, как VideoPlayer подготовит видео и проиграет его, он выпустит это событие. Это событие полезно, если вы хотите проиграть звуки, визуальные эффекты, таймеры или аналогичные эффекты при запуске видео.
Дополнительные ресурсы: VideoPlayer.loopPointReached, EventHandler.
// This script plays some audio when the video starts. // Make sure to assign a VideoPlayer and AudioSource to your GameObject in the Inspector.
using UnityEngine; using UnityEngine.Video;
public class VideoStartExample : MonoBehaviour { VideoPlayer videoPlayer; public AudioSource audioSource; void Start() { videoPlayer = GetComponent<VideoPlayer>();
if (videoPlayer != null) { // Call these functions when the video is prepared and started. videoPlayer.prepareCompleted += OnPrepareCompleted; videoPlayer.started += OnVideoStarted; // Prepare the VideoPlayer. videoPlayer.Prepare(); } }
void OnPrepareCompleted(VideoPlayer vp) { Debug.Log("Preparation done."); videoPlayer.Play(); }
void OnVideoStarted(VideoPlayer vp) { // Play an audio clip when the video starts. Debug.Log("Video has started."); if (audioSource != null) { audioSource.Play(); } else Debug.Log("OnVideoStarted tried to play an AudioSource that doesn't exist."); } }