Search Unity

Video Change Render Mode of VideoPlayer on runtime

Discussion in 'Audio & Video' started by Conkuist, Dec 11, 2019.

  1. Conkuist

    Conkuist

    Joined:
    Apr 9, 2016
    Posts:
    6
    I want to change the rendermode of my VideoPlayer during runtime but it doesn't work.
    Is it even possible to do that or have I missed something?

    Here is an code example of how I was trying to get it done.
    Code (CSharp):
    1. public Material material;
    2. public VideoPlayer player;
    3. public GameObject screen;
    4. private bool flat = false;
    5.  
    6. void Update(){
    7.  
    8. if (flat)
    9. {
    10.   flat = false;
    11.   screen.SetActive(false);
    12.   player.renderMode = VideoRenderMode.RenderTexture;
    13. }
    14. else
    15. {
    16.   flat = true;
    17.   screen.SetActive(true);
    18.   player.renderMode = VideoRenderMode.MaterialOverride;
    19.   player.targetMaterialRenderer = screen.GetComponent<Renderer>();
    20. }
    21. if (player.renderMode == VideoRenderMode.RenderTexture)
    22. {
    23.   RenderTexture texture = new RenderTexture((int)player.width, (int)player.height, 24);
    24.   player.targetTexture = texture;
    25.   material.mainTexture = texture;
    26. }
    27. }
     
    Last edited: Dec 11, 2019
unityunity