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:

        if raycast.is_colliding():
            var b = bullet.instance()
            b.look_at($"../../RayCast".get_collision_point(), Vector3.UP)
            b.shoot = true

        elif not reloading:

if Input.is_action_just_pressed("primary_fire"):

extends Spatial

var add_method = preload("res://Player/Player.gd").new()

func physicsprocess(delta):
if Input.isactionjustpressed("primaryfire"):

extends KinematicBody

classname Playerval

export var currentweapon = 0
func weapon
if Input.isactionjustpressed("weapon1"):
weapon = 1

elif Input.is_action_just_pressed("weapon2"):
    current_weapon = 2

if current_weapon == 1:
    weapon1.visible = true
    weapon1.visible = false

if current_weapon == 2:
    weapon2.visible = true

    weapon2.visible = false

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.