Animating the hero
We are now going to create a script that moves the weapon and the shield items upward then in a downward fashion to simulate a simple breathing look. Let's create another C# script and name it Breather
inside the Scripts
folder. Next, attach the script to both the weapon
and shield
object under the player. Double-click on the script to open it.
First we need to add a couple of variables to store the local position to make our hero breath:
public Vector2 position1; public Vector2 position2;
Then, a third variable stores the time between the two positions defined before:
public float waitTime;
In the Start()
function, we start the coroutine
we are going to implement:
void Start() { StartCoroutine(Mover()); }
Finally, in our coroutine
, we start at a random moment and then there is a main loop that changes between the two positions:
IEnumerator Mover() { yield return new WaitForSeconds(Random.Range...