Trying to do a list of attacks for a Beat em Up.

Hi.

I’m doing a Beat’em Up, and while I did the movement and IA for enemies, I have trouble doing the attack part. What I mean is, I have the characters hit the player when the conditions met, but I have issues related the multiple attacks an enemy can do. I did an “EnemyAttackList” script:

using UnityEngine;
using System.Collections;

public class EnemyAttackList : MonoBehaviour {

	private Animator anim;
	private EnemyActions actionScript;

	public int[] comboList;

	// Use this for initialization
	void Awake () {
		actionScript = GetComponent<EnemyActions>();
		anim = transform.FindChild("Char").GetComponent<Animator>();
	}

	void Start () {

	}

	public void BasicPunch1()
	{
		actionScript.damage = 5;
		actionScript.canLaunch = false;
		actionScript.hitPosition = 1;
		anim.SetInteger("ATK_INT",  comboList[0]);
	}

	public void BasicPunch2()
	{
		actionScript.damage = 5;
		actionScript.canLaunch = false;
		actionScript.hitPosition = -1;
		anim.SetInteger("ATK_INT",  comboList[1]);
	}

	public void Kick()
	{
		actionScript.damage = 10;
		actionScript.canLaunch = true;
		actionScript.hitPosition = -1;
		anim.SetInteger("ATK_INT",  comboList[2]);
	}

	public void JumpKick ()
	{
		actionScript.damage = 10;
		actionScript.canLaunch = true;
		actionScript.hitPosition = 1;
		anim.SetInteger("ATK_INT",  comboList[3]);
	}

	// Update is called once per frame
	void Update () {
	
	}
}

With it, I want to do specific scripts for each enemy using EnemyAttackList as class. Attacks are linked to the animation (it manages the hitbox and sets the end of the attack). But my problem is, I want to “store” those methods on a kind of list from another script, so they became easier to access.

Can anyone help me solve it please? Thanks

use a struct instead with all the stats data

load the stats data from a xml into a struct array so you wont even have to touch your code to change, add or remove attacks

then make a function called attack taking the struct or the array index of the attack.

your code will be cleaner

the second option would be to use delegate but i dont really suggest that approach for that case.