- Home /
Play Animation with int (ammo count)
HI all,
I am trying to recreate the gun from Halo "Type-33 Guided Munitions Launcher" or Needler for a little bit of fun, but its completely thrown me on how I would do it.
I've tried quite a few different ways but I can't find anything that would work.
The gun basically has spikes sticking out of the top of it, (16) (or at least the model of the gun I have has 16), each spike represents 4 bullets. As you shoot, one of the spikes will slowly go down, when it gets to 4, the spike is hidden inside the gun (meaning you've shot it). 16 spikes, 4 each, 64 bullets. Needler
But, I can't figure out how to do this in Unity.
Things I've tried:
Creating a list of Vector3s for each spike moving it into position, then having a loop and / or a (horrible) list of 64 if statements controlling it and moving each spike.
3ds Max - Create an animation for each spike that lowers it into the gun, so Spike 1, Keyframe 1 - 4 is that one going down, Spike 2, Keyframe 5 - 8 is the second spike going down etc... I'm stuck on this one as I don't really want to be creating 64 animation files in Unity to call each one separately (unless there really is no other way).
Some code I looked at was to control the AnimationState.normalizedTime where I found some code by ' syclamoth' Syclamoth's code
but, the animationstate was always null. I tried adding an animation component, playing the animation by default. Also tried with the animator but every time, it was always null when I looked for any state.
Sorry if that's confusing.
Basically, you have a max ammo count of 64 for that gun.
As you fire a single bullet, one of the spikes (in order or random, it doesn't matter) will go down a quarter of the way into the gun.
Fire 4 bullets and one of the spikes disappears.
When you reach 0 ammo, all the spikes need to remain hidden until reload has been triggered.
Any ideas?
Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612130918im_/https://answers.unity.com/themes/thub/images/avi.jpg)