Ok this is not working, have you changed something in Unity 1.1 or what? Code (csharp): //-- Using .mov files as textures on obj: var framesPerSecond = 15; function Update () { //-- Calculate the frame to use by repeating time when it exceeds playLength var FrameCount = Texture.frameCount; var playLength = FrameCount / framesPerSecond; var timeMe = Mathf.Repeat (Time.time, playLength) / playLength; var frame : int = timeMe * FrameCount; frame = Mathf.Clamp (frame, 0, Texture.frameCount -1); Texture.frame = frame; if (frame == FrameCount) { //do something! } }
I get this error: 1.frameCount is not a menber of Unity Texture! 2.frame is not a member of Unity Texture!
This doesn't seem to be a complete script. If it is then, at the very least you are not referencing the texture correctly. the animated texture sample does work correctly: http://www.otee.dk/Documentation/ScriptReference/FileTexture.html
Ok, now why doesn't this work as expected? Code (csharp): //-- Using .mov files as textures on obj: var texture : FileTexture; var framesPerSecond = 15.0; private var stopMovie = true; function Update () { startMovie (); if (stopMovie == false) { frameCount = texture.frameCount; playLength = frameCount / framesPerSecond; time = Mathf.Repeat (Time.time, playLength) / playLength; var frame : int = time * frameCount; frame = Mathf.Clamp (frame, 0, texture.frameCount -1); texture.frame = frame; } if (frame > 39) { //do something! stopMovie = true; finishMe (); } } function startMovie () { yield WaitForSeconds (1.2); stopMovie = false; } function finishMe () { yield WaitForSeconds (3.4); Application.LoadLevel("Menu"); }
Can't really follow the code easily. It would probably be a good idea to nicely indent the code, thus gaining more clarity. anyway one mistake is that you call: startMovie (); But startMovie (); is a coroutine, thus you have to use StartCoroutine or SendMessage to start it.
A coroutine is a function that has a yield statement somewhere in it. Update and FixedUpdate can not be coroutines.
It doesn't seem that I can call coroutine inside Update.. Is there no equalent to a function in Unity? (I just need to call a function inside Update, thats all!).
Of course Unity has functions. But the function you are calling contains a yield. That's the problem. You can not call coroutines directly only normal functions that do not contain a yield.
Hmmm... could this be what you are trying to do? Code (csharp): //-- Using .mov files as textures on obj: var texture : FileTexture; var framesPerSecond = 15.0; var stopAfterFrame = 39; private var stopMovie = true; yield WaitForSeconds (1.2); stopMovie = false; function Update () { if (stopMovie == false) { playLength = texture.frameCount / framesPerSecond; time = Mathf.Repeat (Time.time, playLength) / playLength; var frame : int = time * frameCount; frame = Mathf.Clamp (frame, 0, texture.frameCount -1); texture.frame = frame; if (frame > stopAfterFrame) { stopMovie = true; StartCoroutine("FinishMe"); } } } function FinishMe () { yield WaitForSeconds (3.4); Application.LoadLevel("Menu"); }
That was just the thing! I ended up using a timeleft var and subtracted from that by deltaTime, but your solution is much more elegant and just what I wanted to do! Thanks a bunch!