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
Answer by coolraiman · Apr 05, 2016 at 07:11 PM
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.
I made this struct:
public struct AttackStats
{
public string name;
public int damage;
public bool canLaunch;
public int hitPosition;
}
But I'm not familiarized with both struct and the use of X$$anonymous$$L on Unity, and I don't know how can I access and set values with them :(.
for the sake of simplicity and learning.
create an array of that struct by code also add a constructor in it. A struct constructor force you to assign a value to each variable this will make sure that each variable have a value
I did something that didn't allowed me to edit my structs, but I fixed it using [System.Serializable] and now it works. Thanks a lot!
Your answer
Follow this Question
Related Questions
How to make list of methods (example Sims) 1 Answer
Check if a large number of gameobjects are colliding 1 Answer
Random Teleport Character issue...Help Please. 1 Answer
Arbitrary line in one method prevents another for working? 1 Answer
I can't seem to have access to Tilemap methods, what am I doing wrong ? 0 Answers