Search Unity

Question Video Player Prefab: Render Texture not updating

Discussion in 'Scripting' started by AR_Tehcnoplus, Apr 20, 2022.

  1. AR_Tehcnoplus

    AR_Tehcnoplus

    Joined:
    Jan 17, 2022
    Posts:
    15
    Hi

    I have created a video player prefab, assigned to a list of different game objects. Each game object has a different video attached to it. So, when I am tracking an image I am enabling the video. The sound of the video is correct, but the Render texture is stack and displays a part of another video.

    The code that I have used is :
    Code (CSharp):
    1. public class VideoPrefabBehaviour : MonoBehaviour
    2. {
    3.     private VideoPlayer videoPlayer;
    4.     private VideoClip videoClip;
    5.     DefaultObserverEventHandler parentEventObserver;
    6.     private void Awake()
    7.     {
    8.      
    9.         videoPlayer = GetComponentInChildren<VideoPlayer>();
    10.         if (!videoPlayer)
    11.             Debug.LogError("NO video player component found");
    12.         videoClip = videoPlayer.clip;
    13.         parentEventObserver = transform.parent.GetComponent<DefaultObserverEventHandler>();
    14.         parentEventObserver.OnTargetFound.AddListener(OnTargetFound);
    15.     }
    16.     private void OnTargetFound()
    17.     {
    18.      
    19.         videoPlayer.targetTexture.Release();
    20.         videoPlayer.clip = videoClip;
    21.         videoPlayer.Prepare();
    22.         videoPlayer.prepareCompleted += onPreperationComplete;
    23.    
    24.      
    25.     }
    26.     void onPreperationComplete(VideoPlayer vPlayer)
    27.     {
    28.         videoPlayer.Play();
    29.     }
    30.     void OnEnable()
    31.     {
    32.         videoPlayer.Pause();
    33.     }
    34. }
     
    Last edited: Apr 20, 2022