To ensure that the hero can fight and defeat the enemies, we will give him the ability to shoot magical orbs at the enemies. Let's execute the following steps to do this:
Create an orb GameObject by downloading and unzipping the
Orb.png
sprite from the following URL:http://freeartsprites.com/roguelike/
The orb sprite is shown in the following image:
We name the orb GameObject
orb
.Add a Circle Collider by going to Add Component | Physics 2D | Circle Collider 2D.
Then, go to Add Component | Physics 2D | Rigidbody 2D.
The script is similar to the previous shooting script that we created in Chapter 4, Code Control. The only difference is that we will add conditional checks to make sure that the hero can shoot in all four directions depending on which direction he is facing and traveling.
Add the following code to our hero script:
var orb:Rigidbody2D; var orbSpeed:float = 20f; var orbSpeed2:float = -20f; function Update () { var orbInstance:Rigidbody2D; if(Input.GetButtonDown...