- Home /
MovieTexture duration
I use GUITexture
on screen to play video, by attaching a video to its texture, then on script I want to fade it programatically, but I can't get the length/duration of that MovieTexture
, on the script reference there is duration
variable member of MovieTexture
, but it seems always has value of -1
so how is the correct way to get the length of video or MovieTexture
Answer by lakshmi8 · Nov 16, 2011 at 06:12 AM
Start a timer and know the time for example
void Awake() {
startTime = Time.time;
}
if(movieTexture.isPlaying == true) {
elpasedTime = Time.time-startTime;
}
Now, elapsedTime will return your movieTexture Duration
Answer by lakshmi8 · Nov 16, 2011 at 06:12 AM
We don't have a in built method to read the time but there's a traditional way..
function Awake() {
startTime = Time.time;
}
Now some where in update or OnGUI write this following code..
if(movieTexture.isPlaying == true) {
elapsedTime = Time.time - startTime;
}
Now elapsedTime returns the time taken by the movieTexture
Your answer
![](https://koobas.hobune.stream/wayback/20220612132613im_/https://answers.unity.com/themes/thub/images/avi.jpg)