Cannot cast from source type to destination type for Movie Texture
I am getting this message for all my objects that run a specific script. Here is the script:
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
// Use this for initialization
void Start() {
((MovieTexture)GetComponent<Renderer>().material.mainTexture).Play();
}
// Update is called once per frame
void Update () {
Renderer r = GetComponent<Renderer>();
MovieTexture movie = (MovieTexture)r.material.mainTexture;
if (!movie.isPlaying)
{
movie.Play();
}
}
}
Answer by dkjunior · Oct 15, 2015 at 10:39 PM
You need to add an extra pair of parenthesis so that it casts mainTexture and not Renderer:
((MovieTexture)(GetComponent<Renderer>().material.mainTexture)).Play();
For some reason I keep getting the same error message. The video is playing but the errors persist
Strange... So it compiles fine but shows the error at runtime? What kind of error - is it console log error/warning?
Your answer
Follow this Question
Related Questions
Why does the UI Raw Movie Texture Not Play In Standalone Build 1 Answer
I can't upload some quind of movies 0 Answers
I want to put a tiff secuence as a video 0 Answers
UnauthorizedAccessException: Access to the path 'path to file' is denied. 0 Answers
Video Playback on Mobile Device using GoogleVR Gaze 1 Answer