- Home /
Animated Texture doesn't begin at first frame
Hi, I've been having this problem several times over several projects. I use the Extended Animated Texture script from here
Problem is: I instantiate prefabs with this script, but the animation won't always start at the first frame. Anyone has any idea how to prevent this?
I've found additional information here
I've applied a piece of code that deter$$anonymous$$es the starting time of the instantiated object, which works. But somehow the animation plays really weird, with an fps that seems like 0.5. Also it still doesn't start at the first frame. Can someone shed some light on this issue?
Answer by Seth-Bergman · Mar 14, 2013 at 11:49 PM
going off of your first link, the problem lies with this line:
var index : int = Time.time * fps;
Time.time goes off of the time the game started, what you want is to start with zero.. to do this ,we can zero out the individual time on creation.. just change/add the lines:
var framesPerSecond = 1.0;
var myStart : float; //add this line
function Start(){
myStart = Time.time; //add this
}
function Update(){
var index : int = (Time.time-myStart) * framesPerSecond; //change this
}
this way, we account for the amount of time that has passed between the game start and the creation of the object :)
It's funny, I had the exact same thing except for the ()'s. Apparently, that solved the problem! Thanks man, you're a lifesaver.
order of operations, multiplication comes first...
glad to help!