Hey guys, here is a quick C sharp script for anyone who wants to create thumbnails for their Movie Texture material in Unity. Usually when you play a movie texture,it starts from the first frame or shows a black screen. Below is the script where you just have to drag and drop your Thumbnail and Movie file into this script and it will do the job for you.

using UnityEngine;
using System.Collections;

// Remember to use this script on the 3d object that is playing the movie. 

public class PlayWhenNeeded : MonoBehaviour {

	// Declare the variables for texture(thumbnail) and the movie

	public Texture texture;
	public MovieTexture movie;

	// Use this for initialization

	void Start () {
	
	}

	private void Awake()
	{
		// Enable this to be true if you want the movie texture to be looping
		
                 movie.loop = true;
	}

	// Update is called once per frame

	void Update () {

		// Lets get the renderer component

		Renderer r = GetComponent<Renderer>();

		// When we hit the spacebar key the video will start playing
		// else the movie is paused and the thumbnail is shown

		if (Input.GetButtonDown ("Jump"))
		{
			r.material.mainTexture = movie;
		}
		else 
		{
			movie.Pause();
			r.material.mainTexture = texture ;
		}

	}

}

Hope it helped !

2 Comments

  • PBL says:

    Can you just add details description how to use your script for thumbnails…?

    I have created a plan, and applied your script on to it. Filled Movie Text box with the video i wan to play (.mp4). And Texture field with the thumbnail i would like to show.

    I could able to see thumbnail, but movie is not playing when space is pressed.

    Can you help….? or suggested a solution.

    • Vivek says:

      Hi, if you are using Unity 5 Personal edition I dont think mp4 will play , because its only supported in the pro version.

Leave a Reply