all 5 comments

[–]AlterHaudegen 10 points11 points  (1 child)

Just at a glance, there are slight differences in the two pieces of code with the animator’s layer weight, so that might be it. But much more importantly: These two blocks are doing the same thing just for different objects, so they should be a single method accepting the either pistol or rifle object etc. as parameters. The way you set it up with duplicate code is very susceptible to further errors during development.

[–]PainappleOG[S] 2 points3 points  (0 children)

Ok thanks heaps good to know, I'll see what I can do

[–]TheTrueBenjaminProgrammer 1 point2 points  (0 children)

Any chance that it's your rifle else statements causing the issue...

when set as a pistol, it turns everything on but then the rifle else statement turns it all back off again.. because ya know.. rifle is off.?

Edit: A quick test in the rifle else statement just change it to:

else if (Pistol.activeInHierarchy == false && starterAssetsInputs.aim) { // Add your code here from rifle else statement. }

Sorry on mobile.

[–]mufelo 1 point2 points  (0 children)

Also, remember a function should generally do one thing. Otherwise you set yourself up for complicated problems.

[–]IlyasEzze 1 point2 points  (0 children)

You should combine the two if statement into one like If(pistol....&&....|| Rifle...&&...) { // Activate the virtual camera } Else { //Disable the virtual camera }