I am trying to make very simple gun reload/fire/zoom capabilities. I made animations using the built-in animation-making part of Unity. Now, when playtesting, I am trying to make only one animation be even capable to happen at a time, so a person cannot reload and fire at the same time. However, I cannot find a way to do this. Everything I have found on the forums has been about making them happen at the same time, not what I am trying to do.
I should also mention that my animations are a bit glitchy. For example, if I press right-click to zoom down the ironsights, when I click fire (leftclick), the gun instantly teleports back to the standard position of the gun. Because of this, I cannot fire when zooming. I assume this is because of the animation starting at that point, but I want it to start at the zoom position as well.
If any of you have a good tutorial as to how to do basic gun stuff like this, please post them, especially if they can teach me how to easily switch out weapons, as I cannot find an easy way to use the same scripts for when I have different weapons.
Thank you very much.
Let’s start from the second question: the easy and obvious answer is that you need a second animaiton.
Now as far as playing one animation at a time you can use bools, you can use a state machine. Basically it goes like this:
when you interact with the game you change it’s state, each time you do that you can set and check variables. So
if you are shooting you setup a bool called shooting and when it’s true nothing else can happen, same for reloading etc.
How you implement this is up to you.
Thank you. While I was waiting, I found that I could use the position of the gun using transform.localPosition and check to see if the gun is in the right place if the animation will play or not. However, when I am trying to implement this into the game, I cannot use one static variable to check against all of the animations (because Unity does not like a static transform variable, I don’t know why). So I am having to make a transform variable for each script and it is taking forever. So, instead, I am going to use your idea of a boolean variable (I always forget about those), as it sounds MUCH simpler. I will post again if I run into any problems.