using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
[ExecuteInEditMode]
public class Attack1 : MonoBehaviour
{
private ArrayList animStrings = new ArrayList();
public int maxCombo = 4;
public bool ShowExecuteButton = false;
void Start ()
{
}
void Update ()
{
try
{
if(Input.GetKeyDown(KeyCode.Mouse1))
{
Debug.Log(animStrings.Count);
animStrings.RemoveAt(animStrings.Count-1);
}
}catch(ArgumentException e){Debug.Log(e);}
}
void OnGUI()
{
if(animStrings.Count < maxCombo)
{
if(GUI.Button(new Rect(25, 25, 75, 50), "Attack"))
SaveAnimations("Attack");
if(GUI.Button(new Rect(25, 75, 75, 50), "Attack01"))
SaveAnimations("Attack01");
if(GUI.Button(new Rect(25, 125, 75, 50), "Attack02"))
SaveAnimations("Attack02");
if(GUI.Button(new Rect(25, 175, 75, 50), "Combo"))
SaveAnimations("Combo");
}
if(animStrings.Count == maxCombo && !ShowExecuteButton)
{
if(GUI.Button(new Rect(125, 85, 125, 50), "Execute"))
{
StartCoroutine(ExecuteAnimations(0));
ShowExecuteButton = true;
}
}
try{
GUI.Label(new Rect(125, 300, 100,50), animStrings[0].ToString());
GUI.Label(new Rect(175, 300, 100,50), animStrings[1].ToString());
GUI.Label(new Rect(225, 300, 100,50), animStrings[2].ToString());
GUI.Label(new Rect(275, 300, 100,50), animStrings[3].ToString());
}catch(ArgumentException e){Debug.Log(e);}
}
void SaveAnimations(string anim)
{
animStrings.Add(anim);
}
IEnumerator ExecuteAnimations(int counter)
{
for(int x = 0; x < maxCombo; x++)
{
animation.Play(animStrings[x].ToString());
yield return new WaitForSeconds(1);
}
for(int x = 0; x < maxCombo; x++)
{
animStrings.RemoveAt(0);
}
ShowExecuteButton = false;
yield break;
}
}
is this the best method to make the “Execute” button appear when the array is already full and the arraylist appears everytime i clicked a button? since there is an ArgumentException even if i’m just gonna call it in the if statement.
you can use Count. if(animString.Count == maxCombo)
– ziv03wow. I feel dumb now! btw is it okay to try-catch the GUI.label like the above code or there is another way to show it without the argumentexception?
– jvt619If animString is an array then you have no reason to feel dumb because Count is not an array member but a list member. The equivalent for array is Length. But you need to show more of your script because this is no telling us how you fill the array/list or what should be the problem. On top of that the ArgumentException is not related to a full array, it is because you are passing an argument that is not appropriate.
– fafasejust posted the full script.
– jvt619