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:

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!

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.

Many thanks! Made my life much easier. :slight_smile: