STEP3: Improve the Visual Script.
- Select the Idle state and add 3 actions. The first is ChangeObjectProperty. Set the property of your own node, W005Gun’s Visible, to Off.
- The second is also ChangeObjectProperty. Set the property of your own node, W001Sword’s Visible, to Off.
- The third is also… ChangeObjectProperty. Set the property of your own node, AttackCollision’s Disabled, to On.
- Try a test play. The sword and gun should disappear, and even if you ram into a zombie, the zombie should not take damage. However, since they remain invisible, next we will enable their display.
- In the Sword state, do the reverse of the previous steps. Add 2 actions. Using ChangeObjectProperty, set the property of your own node, W001Sword’s Visible, to On.
- Using ChangeObjectProperty, set the property of your own node, AttackCollision’s Disabled, to Off.
- Let’s try a test play. If set correctly, the sword should only be visible during sword attacks.
- Next is the gun. In the Shoot state, add just one action, again using ChangeObjectProperty, and set the property of your own node, W005Gun’s Visible, to On.
- Let’s try a test play. The gun should now only be visible when firing.
TIPS
Switching Properties Using Animations
In this course, we switched the visibility of each sprite using the ChangeProperty action, but this behavior can also be performed using Animation.
Since properties can be set as keyframes, please note that the switch will only occur when the animation plays up to that point. If you switch animations midway, the visibility switch may not work correctly.
In fact, some animations, such as 026_Crouch, use animations to switch expression polygons.
For how to use AnimationPlayer, please refer to the Graphics Course.
The fourth session is here:





