Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | quackedup |
Hey all I’m using the script below for a bullet in my game, however when detecting an enemy I want to remove some of it’s HP, but nothing worked I tried. I want to access the script attached to the collider then a variable inside that script.
extends KinematicBody2D
var speed = CharacterSheet.gun_bullet_speed
var bruuuuh
var time_left = 100
func _physics_process(delta):
bruuuuh = speed * transform.x
move_and_slide(bruuuuh)
time_left -= 1
if 0 >= time_left:
queue_free()
for index in get_slide_count():
var collision = get_slide_collision(index)
if collision.collider.is_in_group("enemy"):
pass
#Want to access "ScriptName" in the collider and the health variable
inside that
collision.collider.ScriptName.health -= CharacterSheet.gun_damage
queue_free()
elif collision.collider.is_in_group("player"):
print("stuff")
elif collision.collider.is_in_group("bullet"):
pass
else:
queue_free()