Continuing with the enemy, in this lesson we will create hp for the enemy and this lesson is quite short, in the next lesson I will guide you to create slash animation (because the available assets of anonyviet do not have slash animation so I will use another animation and if anyone uses another asset that has attack animation then just use it) and destroy the enemy.
Join the channel Telegram belong to AnonyViet 👉 Link 👈 |
USE EXPORT
Go to the enemy script section and declare your HP variable.
I will declare that:
export var hp = 2
And Export here is the declaration command to bring the value out of the table. Properties to edit
You can also do the same with variables if you want and Export it has nothing to do with your code, it only has the function of bringing the variable value out for easier editing without having to edit the code.
And you can apply this to many other things.
Here I will guide you a trick to choose something like color, etc.
Export (String,”text”) var variablename 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)
If statement to compare what color is selected
$Call sprite or AnimationSprite or whatever and modulate to change the color
You can func create a function containing the color change command and then call the color change function in physics or process
For example:
# 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)