Selecting an attack

The player will select an attack and then select the enemy to perform the attack. To allow the player to select various attacks from the HUD, we will create a new script called Attack in the Assets/Scripts folder, as follows:

using UnityEngine; 
using System.Collections; 
 
public class Attack : MonoBehaviour { 
 
    public bool attackSelected=false; 
    public int hitAmount=0; 
 
    public void Smack(){ 
        hitAmount=5; 
        AttackTheEnemy(); 
    } 
 
    public void Wack(){ 
        hitAmount=10; 
        AttackTheEnemy(); 
    } 
 
    public void Kick(){ 
        hitAmount=15; 
        AttackTheEnemy(); 
    } 
 
    public void Chop(){ 
        hitAmount=20; 
        AttackTheEnemy(); 
    } 
 
    public void AttackTheEnemy(){ 
        attackSelected=true; 
    } 
}  

Essentially, when each button is hit, it will reference a different attack with a different hit ...

Get Mastering Unity 2D Game Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.