Adding Effects to our player
Creating an swing effect for our player attack animation
Now that we have our swing animation, we can spice it up by adding some visual effects during the animation sequence. We will be working on how to create an new animation state and working with the player Animation script to toggle the animation trigger.
Arc Effect Setup:
First we are going to import and slice the animation sheet into individual frames. Drag the first frame into the hierarchy and make the first frame a child of the player game object. Then we are going to create a new Animation for the Arc effect and dragging in all of the divided images into the dopesheet.
Next in the Animator window we need to create a new default state to prevent the sword arc effect to play immediately after launching the game. We need to create a new Trigger parameter to toggle the transition between the Idle and Sword Effect.
Player Animation script:
In the player animation script, just like how we have reference the animator in the sprite object, we need to do the same for the sword effect.
In the Start method, since both the sprite and the sword effect are children of the player object, we can’t use “Get component in children” anymore since there will be a confusion between the two game objects. Therefore in Unity, we can use an new type of identification. Since everything within the Hierarchy is based on a “hierarchy” we know that the first component is rated at Zero, and the next object starts at 1. Since the “Sword_Arc” component is second in the list, we can type out “Transform.Getchild(1)” before we get the component.
Finally during the attack phase, we can also implement the arc animation as well.
Now when you attack, there should be an sword effect that plays along with it.