Skip to content
User Avatar
#3750
Auto-translated
Jewily
The best optimization option is to implement it only when you initiate the attack. How you do it is up to you. In general, I haven't done this myself, but if you attach a trigger to your hero that activates on touch, you can "disable" the standard attack and, using this trigger, enable interaction and `MakeHeroInterractWithObject` (or something like that), effectively making the hero attack the enemy. Then you'll only need one script.
I might be wrong about disabling the standard attack, but you can experiment with `SetObjectEnabled` and so on. There are many workarounds you can come up with. For example, you could create a loop that checks the distance between your heroes, and if the distance is 2 tiles, your hero will attack the enemy using this script... (but I wouldn't recommend this option )
Yes, it's a pity that you can't pass heroes as arguments. Unfortunately, nothing I tried in the combat script itself worked. I tested it on the `playAnimation` function and constantly received the error "Hero "hero" doesn't exist," so I came to the conclusion that the combat script is essentially a separate script, so you can load it up a bit. Therefore, I will define the fight twice, depending on which side the heroes are on. However, thank you for your answer and recommendation