So I have a light rig attached to a bone. This bone carries a script specifically for the 3 lights.
extends BoneAttachment
var light_on = 1
func _input(InputEvent):
if Input.is_action_pressed("light_on_off") && light_on == 1:
$Flashlight/FlashlightAnim.play("FlashlightOFF"); light_on = 0;
elif Input.is_action_pressed("light_on_off") && light_on == 0:
$Flashlight/FlashlightAnim.play("FlashlightON"); light_on = 1;
If I press the middle mouse button while no other input is being added (such as mouse rotation or keyboard presses) it works well most of the time (lights turn off/on). But if I press it while also doing anything else, the light tends to act as if I've rapidly double clicked, so it goes from state light_on ==1 to state light_on == 0 and back to state light_on == 1. How do I make it not do this? I'd add some kind of timer in between but not sure how.
I tried to use just if instead of elif but it does absolutely nothing but stays on.
EDIT nvm, I changed it to this and it seems to work:
extends BoneAttachment
var light_on = 1
func _physics_process(delta):
if Input.is_action_just_pressed("light_on_off") && light_on == 1:
$Flashlight/FlashlightAnim.play("FlashlightOFF"); light_on = 0;
elif Input.is_action_just_pressed("light_on_off") && light_on == 0:
$Flashlight/FlashlightAnim.play("FlashlightON"); light_on = 1;