Im really new to godot and im trying to get a gun to work but my script says Line 12:Unexpected “if” in class body. (which i dont know how to fix)
(here is my script)
extends RigidBody3D
var mouse_senstivity :=0.001
var twist_input :=0.0
var pitch_input := 0.0
@onready var twist_pivot := $TwistPivot @onready var pitch_pivot := $TwistPivot/PitchPivot @onready var gun_anim := $TwistPivot/PitchPivot/Camera3D/Gun/RootNode/Shotgun_SawedOff/AnimationPlayer
#shooting
if Input.is_action_pressed(“shoot”): (HERE IS WHERE THE ERROR IS)!!!
Every script is a class definition, meaning you cannot write code you expect would execute as is. Every instruction you want to execute should be put in a dedicated block.
You can think of functions, property defintions, …
E.g
func my_function():
print("This is an instruction!")
Or for properties
var my_property: int = a:
get:
print("Getter block !")
return 3 * my_property
set(value):
print("Setter block !")
my_property = value / 2
There are also variable assignations within definitions which support short expressions !
var my_var: int = compute_int()
var my_other_int = 3 * my_int
Either way, aside from those main 3 cases (and if I did not forget any), you can’t write instructions anywhere else
Also, you have two problems with that line of code. Line 12 needs to be inside your _process() function, and you have to have it do something after that on the next line. (That error is hidden right now because of the other one.)