Hi
I wrote a script for Combo attack. It supposed to just have different animations for each attack, also Attack 1 and 3 are made by right arm, Attack 2 by left.
The problem is the character ionly permorms Attack 3. Am I just too naive thinking that playing with attack = true/false would work, lol?
public class PlayerCombat : MonoBehaviour
{
public Transform attackPoint;
public Transform attackPoint2;
public float attackRange = 0.5f;
public LayerMask enemyLayers;
public int attackDamage = 40;
public float attackRate = 2f;
public Animator animator;
bool Attack1;
bool Attack2;
bool Attack3;
void Start()
{
Attack1 = true;
Attack2 = false;
Attack3 = false;
}
void Update()
{
if (Attack1 == true && (Input.GetKeyDown(KeyCode.P)))
{
Attack_1();
Attack1 = false;
Attack2 = true;
}
if (Attack2 == true && (Input.GetKeyDown(KeyCode.P)))
{
Attack_2();
Attack2 = false;
Attack3 = true;
}
if (Attack3 == true && (Input.GetKeyDown(KeyCode.P)))
{
Attack_3();
Attack3 = false;
Attack1 = true;
}
}
void Attack_1()
{
animator.SetTrigger("Attack1");
//Detect enemies
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
//Damage them
foreach (Collider2D enemy in hitEnemies)
{
enemy.GetComponent<Enemy>().TakeDamage(attackDamage);
}
}
void Attack_2()
{
animator.SetTrigger("Attack2");
//Detect enemies
Collider2D[] hitEnemies2 = Physics2D.OverlapCircleAll(attackPoint2.position, attackRange, enemyLayers);
//Damage them
foreach (Collider2D enemy in hitEnemies2)
{
enemy.GetComponent<Enemy>().TakeDamage(attackDamage);
}
}
void Attack_3()
{
animator.SetTrigger("Attack3");
//Detect enemies
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
//Damage them
foreach (Collider2D enemy in hitEnemies)
{
enemy.GetComponent<Enemy>().TakeDamage(attackDamage);
}
}
private void OnDrawGizmosSelected()
{
if (attackPoint == null)
return;
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
if (attackPoint2 == null)
return;
Gizmos.DrawWireSphere(attackPoint2.position, attackRange);
}
}
Animation settings: