Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
CakeMonsTv

Reload script bug

Question

Hi. 

I know that this seems to be a lot, but trust me it's really not. It's just that its all connected. The actual part you need to help me with is like 1/5 of the script.

 

 so i've been rewriting my reload script. I ran into a bug that I can't figure out how to fix. I literally spent 2 hours trying to.. So I wanted to make it so the player will put 2 bullets intro the gun if only 2 bullets are missing from magazine. Or for example i shoot 3 bullets, he will reload 3 bullets. I made 2 animations, first one is inital animation and puts 1 bullet in, and second is just to put 1 bullet in (the second one should be repeated in the process). So lets say the magazine is missing 3 bullets. First we play 1st animation and then 2 times the 2nd one.

 

1st

Please login or register to see this link.

2st

Please login or register to see this link.

 

Animator:

Please login or register to see this link.

 

Code (Explaination below)

 

Please login or register to see this code.

When i fire or do R, it jumps to doReload function, There it checks if secondReload is true and if not, plays 1st animation.

 

Script of 1st animation:

Please login or register to see this code.

Then here after animation is finished It calls reload function in above script. There it checks if there are any bullets at all left, if yes then it decreases by 1 bulletsleft value, makes secondReload true, adds 1 bullet/value to the magazine/clip and calls doReload. There it play 2nd animation since secondReload is true. 

 

The problem is that when I fire all bullets (5 per magazine/clip), it runs 1st animation once and 2nd animation once. After that i fire those 2 bullets as well and it runs only 1st animation (Please login or register to see this link. )

 

Whoever solves this or atleast tries I thank you so much!

Edited by CakeMonsTv
Added something

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

I can't really see through your script but that's how I would do it:

Please login or register to see this code.

You should set the reload animation's wrap mode to "Once" so it only plays once and doesn't repeat.

One thing to be aware of is that this whole WaitForSeconds and stuff falls apart if you have them running multiple times.

Please login or register to see this code.

Btw this way you don't need multiple methods for the reloading, I don't even know why would you ever use fixed update for anything which is related to the reloading anyways.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...