Continuing with the enemy, in this article we will create hp for the enemy and this article is quite short, in the next post I will guide you to create slash animation (because anonyviet’s available assets do not have slash animation, so I will get animation. and if you use another asset that has an animation attack, use it) and kill the enemy.
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
USE EXPORT
Go to the script enemy and then you declare your HP variable
I will declare as:
export var hp = 2
And Export here is the declaration command that takes the value out of the table Properties to edit
You can also do with the same variables if you want and Export it has nothing to do with your code, it just has the function of putting the variable value out for easier editing without having to edit the code.
And you can apply it to many other things
Here I will show you a trick to choose something like color etc
Export(String,”text”) var tenbien is to be
Here if you want to change the color, you code as follows:
if ColorMode == "Mau Do": $Sprite.modulate = Color(0, 0, 1, 1) elif ColorMode == "Mau Xanh": $Sprite.modulate = Color(0.75, 0.75, 0.75, 1) elif ColorMode == "Mau Cua Anonyviet": print(“Dep Trai Khong Bao Gio Sai)
What color is the if statement to compare?
$Call sprite or AnimationSprite or whatever and modulate to change color
You can func create a function that contains the command to change the color and then call the function to change the color in physic or process
Examples are as follows:
# ham process goi du lieu ben trong tren tung khung hinh Func _process(delta): #goi set color Setcolor() # ham set color Func setcolor(): if ColorMode == "Mau Do": $Sprite.modulate = Color(0, 0, 1, 1) elif ColorMode == "Mau Xanh": $Sprite.modulate = Color(0.75, 0.75, 0.75, 1) elif ColorMode == "Mau Cua Anonyviet": print(“Dep Trai Khong Bao Gio Sai)