0 votes

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.isactionjustpressed("primaryfire"):
if currentammo > 0 and canfire 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 physicsprocess(delta):
if Input.isactionjustpressed("primaryfire"):
axeplayer.play("Axecut")

extends KinematicBody

classname Playerval

export var currentweapon = 0
func weapon
select():
if Input.isactionjustpressed("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.

in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.