How can I access the elements of a mesh render from a c# script?

I have a gameObject with two planes in it. Each plane has a movieTexture attached to it.

65787-capture.jpg

I have a C# script attached to this object. How can I access these movieTexures in my script? I am trying to access them like this:

public class MyClass: MonoBehaviour
{
    public MovieTexture movie;
    public MovieTexture movie2;

     Material[] materials;

    void Start()
    {
        movie = materials[0] as MovieTexture;
        movie2 = materials[1] as MovieTexture;
    } 
}

But I get this error:
“Cannot convert type ‘UnityEngine.Material’ to ‘UnityEngine.MovieTexture’ via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion”

Line 10:

movie = materials[0].mainTexture as MovieTexture;

You want the texture as movie texture materials[0] is just the first material which is NOT a movie texture :wink: