Search Unity

Using a Movie Texture with uGUI

Discussion in 'UGUI & TextMesh Pro' started by DanSuperGP, Sep 23, 2014.

  1. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    Is there any way to use a Movie Texture with the new UnityGUI?

    I'd love for the movie to be a part of my UI and take advantage of the anchoring and other features of a rect transform.
     
  2. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    I figured it out, it is already supported with RawImage. You just need to get the mainTexture component of the main image and cast it to a movie texture to start it playing.
     
    Tim-C likes this.
  3. vuong_vin

    vuong_vin

    Joined:
    Sep 17, 2014
    Posts:
    18
    Hey Dan, could you please let more detail or show some guide. Thanks
     
  4. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    It's easy. You just add a Raw Image component, then assign a Movie Texture to the .texture property of the Raw Image. You then can cast the .texture property to a movie texture to access the methods like play, stop, loop, etc.

    Obviously you have to have Unity Pro or you won't have movie textures.
     
    vuong_vin likes this.
  5. vuong_vin

    vuong_vin

    Joined:
    Sep 17, 2014
    Posts:
    18
    Hello Dan,

    Trying to play from mainTexture but can not RUN. Could you help me more? Thanks
     
  6. mrgoonie

    mrgoonie

    Joined:
    Jan 7, 2015
    Posts:
    6
    Hello quenhoai2003,

    I know it has been late, but I think I would post the answer here, so people who has the same question will know how to do it (I actually has just figured it out myself)

    1. Create new Raw Image.
    2. Drag the video into the Raw Image, so the video will be its texture. But now it doesn't play yet.
    3. To make it play, add this new script:

    (remember to add: "using UnityEngine.UI;" on the top)

    MovieTexture movie = GetComponent<RawImage>().texture as MovieTexture;
    movie.Play();​

    Now the video will be played, but the sound is not.

    4. Add the new component call "Audio Source" into the Raw Image. Then back to the script, write down this:

    AudioSource sound = GetComponent<AudioSource>();
    sound.clip = m.audioClip;
    sound.Play();​

    There you go!

    Cheers,
     
    vuong_vin likes this.
  7. PrinceOfUnity

    PrinceOfUnity

    Joined:
    Jun 16, 2013
    Posts:
    4
    Hey It's giving "error CS0116: A namespace can only contain types and namespace declarations" what can I do?
     
    vuong_vin likes this.
  8. mrgoonie

    mrgoonie

    Joined:
    Jan 7, 2015
    Posts:
    6
  9. vuong_vin

    vuong_vin

    Joined:
    Sep 17, 2014
    Posts:
    18
    Hello mrgoonie, Thanks for your support, but its just play with preview in unity, when i build for ipad it have error: "Error building Player because scripts had compiler errors".

    Did you ever build it out?

    Thanks and Happy Lunar new year.
     
  10. llde_chris

    llde_chris

    Joined:
    Aug 13, 2009
    Posts:
    205
    MovieTextures aren't available on mobile.

    Movies on mobile are played fullscreen using the Handheld class.
     
  11. cadpeople

    cadpeople

    Joined:
    Nov 6, 2014
    Posts:
    21