How to get right click pressed one time? (SOLVED)

Hello guys! I am Japanese so I am not good at English sorry.

By the way, I have a problem on my project.
↓ This is my cord .

function on_input(self, action_id, action)
  if action_id == hash("rightclick") and action.pressed then
    print("rightclick_pressed")
  end
end

But it send me 3 times per 1 right click.
So, I tried to count it , but it doesn’t work.

You can use on_input only to save that input is active. Then on_update to process it. This way you only get 1 input per frame instead of the multiple you sometimes can see. Then at end of on_update disable all of these bools.

function update(self, dt)
  if self.rightclick_pressed then
    print("rightclick_pressed")
  end
  self.rightclick_pressed = false
end

function on_input(self, action_id, action)
  if action_id == hash("rightclick") and action.pressed then
    self.rightclick_pressed = true
  end
end
1 Like

I tried it , but it doesn’t change the situation…

P.S. on_update(self, dt) >> update(self, dt)

I think that it processed same time.

Try replacing action.pressed by action.released In your original code

1 Like

It also doesn’t change…

Is the script attached to multiple gameobjects?

2 Likes

Oh! You are right!
I skipped collision check…

Thank you for your support :smiley:

3 Likes

You’re right it’s update not on_update although looks like problem was something else!

2 Likes