Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Mifa |
Hello everyone I am new to this forum.
I’m wondering if it’s possible to put two different functions on one mouse button.
for example:
if button number 1 is a rifle with its animations and sound effects.
and if button 2 is an ax with its animations.
What they have in common is the left mouse button, when I press the number 1 button and press the left mouse button to show the animation of the rifle, and when I press the number 2 button and press the left mouse button, I get animation and ax effects.
here is my code:
extends Spatial
class_name Weapon
var add_method = preload(“res://Player/Player.gd”).new()
var per = preload(“res://Player/Axe.gd”).new()
if Input.is_action_just_pressed(“primary_fire”):
if current_ammo > 0 and can_fire and not reloading:
fire()
anim_player.play(“Fire”)
if raycast.is_colliding():
var b = bullet.instance()
muzzle.add_child(b)
b.look_at($"../../RayCast".get_collision_point(), Vector3.UP)
b.shoot = true
elif not reloading:
reload()
if Input.is_action_just_pressed("primary_fire"):
per.strikes()
extends Spatial
var add_method = preload(“res://Player/Player.gd”).new()
func _physics_process(delta):
if Input.is_action_just_pressed(“primary_fire”):
axe_player.play(“Axe_cut”)
extends KinematicBody
class_name Player_val
export var current_weapon = 0
func weapon_select():
if Input.is_action_just_pressed(“weapon1”):
current_weapon = 1
elif Input.is_action_just_pressed("weapon2"):
current_weapon = 2
if current_weapon == 1:
weapon1.visible = true
else:
weapon1.visible = false
if current_weapon == 2:
weapon2.visible = true
else:
weapon2.visible = false
issue:
Occurs when I select for example button number 1 and press the left button I get two effects in one the sound of a shot fired from a rifle and the blow of an ax from a tree
If anyone can help me thanks in advance.