Is this script attached to the gun? If so, either move your input check to a script on the player (my actual recommendation), or set shootAble to false by default. Only set shootAble to true if it is in the player’s hand.
Yes it is attached, how would I set shootAble to true if its in the players hand and when you say move, so delete it from this script and add it to a player script?
Edit: So i did move it to the player script, now i have 4 errors and there all cs0103, 2 for shootAble, 1 for Shoot, and 1 for ShootingYield.
I’d assume there is some code you run when you attach the gun to the player’s hand. You’d set shootAble to true in that code. In whatever code you run when you remove the gun from the player’s hand, you set shootAble to false and also kill all of the gun’s coroutines.
No one memorizes error codes. Unity gives a descriptive error with line numbers.
Okay so I did that to which fixed a lot of it to now I’m stuck with one more error to which says, “Type ‘PickupScript’ already defines a member called ‘Update’ with the same parameter types”
How would I fix this?
Okay, now its saying how, ‘shooting’ and ‘ShootingYield’ does not exist in the current context. What would I need to do to fix this? Sorry for asking a lot and errors but thanks.
You might want to take some C# tutorials, as these are really basic C# issues which aren’t really related to Unity. If you call a method, you either call it as part of the same class, or you need a reference to the instance of the class you are calling the method on (with some exception). So if you want to call “shooting” from this other class now, you need a reference to the object which actually has the shooting method, and you call it on that reference. When I suggested moving your input check over to the player, I wasn’t suggesting to just cut/paste your existing code. You’d have to redesign your system so you check for input on the player, and then call the proper method on the gun object.
When you pick up the gun you’d probably want to store a reference to the gun. Then when the player tries to shoot, you call a method on the gun that starts it off. That method would handle the shooting of the gun and the starting of any coroutines on the gun, since the player object shouldn’t really need to know how the gun works (as it is generally bad design otherwise).
I don’t have a specific suggestion, since I learned C# when learning from actual printed books was still the norm, but I know Unity has their own C# essentials tutorials, and since it is an industry standard language there are an endless number of tutorials and even classes which teach C# unrelated to Unity.