- Home /
Gun Ammo Counter - Set frame of sprite sheet
Hey guys,
I'm got a sprite sheet of numbers that I'm using along with the AnimatedTextureExtendedUV.js from Here.
The sprite is set to a plane, that I align with my guns model to give it a halo styled ammo counter built onto the gun, like this:
http://hce.halomaps.org/images/files/lg/AR.jpg
Now it works perfectly, the plane runs through the animation just fine. What I'm looking to achieve is to be able to actually set the frame of the script to any frame I want, to represent how much ammo is in the weapon.
I looked at the script and the only thing that I'm getting from it is that the frame might be controlled by this:
// Calculate index
var index : int = Time.time * fps;
// Repeat when exhausting all cells
index = index % totalCells;
However, I have no clue as to how to change this to a variable that I can set. Whenever I tried, it came up with a different frame to the one I wanted.
Does anyone have any insight on this?
Many thanks!
Answer by syclamoth · Jan 23, 2012 at 02:46 AM
Well, it's pretty straightforward. Have a public member variable at the top of your script-
var curFrame : int = 0;
and then change those lines to
var index : int = curFrame;
index = index % totalCells;
When you want to change the current frame, modify curFrame. It will automatically wrap back to the start if you give it too high a number.
Your answer
Follow this Question
Related Questions
Gun Script not working help please 2 Answers
Why animation events do not change sprite position? 1 Answer
Dependency sprite animation from the variable 0 Answers
Unity Sprite Editor Error 0 Answers