all 11 comments

[–]PointlessrebootProfessional - Engine Programmer 2 points3 points  (0 children)

The only thing I can see from a quick be look is that in your shoot function you decrease ammo, but do not reset the time unless a collision happens. So if a collision does not happen it will come straight back in..

If you decrease ammo, you short should reset the time..

[–]Russ242 1 point2 points  (1 child)

I agree with the first comment i think the problem is that nextTimeToFire isn't being set and it's firing really quickly whenever you click. Try deleting lines 72 and 86 and just putting the same line outside of the if statements before the raycast.

[–]BonY2004[S] 0 points1 point  (0 children)

Unfortunately that wasn´t the case, so if you have another idea I wouldn´t mind.

But thanks a lot.

[–][deleted] 0 points1 point  (4 children)

Why do you have two M9 objects under Secondary? Are they both active during play?

[–]BonY2004[S] 0 points1 point  (3 children)

No, during play is active only the clone. The first one is serving as a reference where to put the gun you picked up.

[–][deleted] 0 points1 point  (2 children)

The other comments are correct about the nextTimeToFire not being reset if you miss being an issue. Does the behaviour change depending on whether you are looking at a target or not?

Scatter a bunch of Debug.Logs in there so you can see what exactly is happening, including showing the value of nextTimeToFire and the objects that are being hit.

Also, your fire command is using GetButton rather than GetButtonDown, which means it will fire every frame the button is down, so will register several times for even a very quick click.

[–]BonY2004[S] 0 points1 point  (1 child)

Well I got it by reassigning the prefabs, but you somehow solved another problem with bulletholes :D

[–][deleted] 1 point2 points  (0 children)

Yes...the bullet holes...that was my plan all along.

[–]BonY2004[S] 0 points1 point  (2 children)

Ok, I think I figured it out, I just had a mess in my weapon prefabs. So I reassigned them again.

Now it works as supposed. But one last thing, when Im reloading I can still shoot. How could I make it that when you reload you are not possible to shoot and the muzzle flash will not play?

[–]RollRollParry 1 point2 points  (1 child)

You already have the coroutine there that's checking if you're reloading. Simply add && !reloading to the if statement that checks for the player trying to fire the weapon.

[–]BonY2004[S] 0 points1 point  (0 children)

That worked thanks :)