video code not playing

hi, i make c code to play video in unity3d but not working and appear this error what can i do

An object reference is required to access non-static member `UnityEngine.Material.mainTexture’

and this my code

using UnityEngine;
using System.Collections;

[RequireComponent (typeof (AudioSource))]

public class video : MonoBehaviour {

public MovieTexture movie;

// Use this for initialization
void Start () 
{
	Renderer.material.mainTexture = movie as MovieTexture;
	movie.Play ();
}

}

and also in javascript this code not work

renderer.material.mainTexture.play();

[RequireComponent (typeof(AudioSource))]

public class VideoPlay : MonoBehaviour {

public MovieTexture movie;

void Start () {
	renderer.material.mainTexture = movie as MovieTexture;
	audio.clip = movie.audioClip;
	movie.Play ();
	audio.Play ();
}


void Update () {

}

}

Try this code

I just noticed in the comments that you’re wanting to do this on Android. You should really try to include such details in your question as it effects the answer!

As far as I can tell, this is not a supported feature on Android. There are workarounds though.

The Unity docs seem to give everything you should need to know: MovieTexture Manual and Handheld.PlayFullScreenMovie.

Hope that helps. I’ll leave my answer below this as it answers the question as you’ve asked it.

==================================================================

Your problem is that you’re trying to access the renderer’s material as if it is a static variable (belongs to the class), when it is an instance variable (belongs to the instance).

What you want to do is use GetComponent() to get the Renderer you’re after (there will certainly be many Renderers in your scene, which is why you have to get the instance rather than the whole class). It wouldn’t make sense for the material properties to be static features of the Renderer class!

sujit11dec is along to right tracks, and his solution will work in older versions of Unity. However, in Unity 5 they removed some “shortcuts” to accessing components (which deceptively look like variables).

Here:

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(AudioSource))]
public class video : MonoBehaviour {

 public MovieTexture movie;
 
 // Use this for initialization
 void Start () 
 {
     GetComponent<Renderer>().material.mainTexture = movie as MovieTexture;
     movie.Play();
 }
}

It might be worth reading up on classes and static variables/functions. It’s reasonably simple (and key/core!) stuff, but you might find it helpful to get a better grasp of some of the core concepts for future work.

Hope that all works out for you =).