Random Damage for each scene using same hitbox code

hi i would like some help with this
heres the code for hitbox


as u can see damage is 10 but in scene i chosed for this bullet dmg to be 2
how do i add random number for damage i want for any type of bullet i want with same script? like i want this bullet to do damage between 1-3 but when i load script in other scene i want it to do 7-11 damage without changing first bullet’s damage

you can do two export variables that define the range of the damage and then add a method that gives a random-number between them:

class_name Hitbox extends Area2D

@export var damage_floor:= 5
@export var damage_ceiling:= 7

func get_random_damage() -> int:
    return randi_range(damage_floor, damage_ceiling)

Thanks it works perfectly

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.