I am trying to have a TextureRect update with an input. The child has the script below.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sabir_The_Trubbish

extends KinematicBody2D

var charge = 0

func _ready():
pass
func _physics_process(delta):
chargeFunc()
func chargeFunc():
if Input.is_action_pressed(“attack”) and charge > 4:
charge = charge + 0.5

var chargeBar = get_parent()
if charge == 4:
	chargeBar.texture = load("res://UI/FullCharge.png")
if charge == 3:
	chargeBar.texture = load("res://UI/Charged3.png")
if charge == 2:
	chargeBar.texture = load("res://UI/Charged2.png")
if charge == 1:
	chargeBar.texture = load("res://UI/Charged1.png")
if charge == 0:
	chargeBar.texture = load("res://UI/EmptyCharge.png")

if Input.is_action_just_released("attack"):
	charge = 0
:bust_in_silhouette: Reply From: exuin

It looks like it’s impossible for charge to ever be greater than 0 since it’s only incremented when charge is greater than 4.

Also, I think you should look into using match statements instead of having many separate if statements. Also, I’m not sure if you want to run this code in _physics_process. It sounds like it might increment the charge counter too quickly? Maybe consider using a Timer?