- Home /
the attack is synchronized if there is more than one enemy
so basically when my Hero in rage of enemy attack the animation is start to paly and enemy is attacking that all cool and it's working, but if i make the clone of enemy and place the enemy clone else where, and when my hero in rage of original enemy they both start to attack. Can some one help me to fix this.
This is my scritps:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChimeraAnt : MonoBehaviour {
public float moveSpeed = 20f;
public int maxHealth = 100;
public int currentHealth;
public HealthBar healthBar;
public Rigidbody2D rb;
int dir = 1;
Vector3 localScale;
public static bool isAttacking = false;
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
currentHealth = maxHealth;
healthBar.SetMaxHealth(maxHealth);
}
// Update is called once per frame
void Update () {
if (isAttacking)
anim.SetBool ("isAttacking", true);
else
anim.SetBool ("isAttacking", false);
if (currentHealth <= 0)
{
anim.SetTrigger("Death");
moveSpeed = 0;
}
}
void FixedUpdate()
{
if (!isAttacking)
rb.velocity = new Vector2(moveSpeed*dir*Time.deltaTime,rb.velocity.y);
else
rb.velocity = Vector2.zero;
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.name.Equals("HandAttack"))
{
TakeDamage(25);
Debug.Log("hand attacked!!!!");
}
}
private void OnTriggerEnter2D(Collider2D other) {
if (other.tag == "rWall" || other.tag == "lWall") {
dir*=-1;
Flip();
}
}
private void Flip() {
transform.Rotate(0,180,0);
}
void TakeDamage(int damage)
{
currentHealth -= damage;
healthBar.SetHealth(currentHealth);
}
}
and this is Damage Controller script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DamageController : MonoBehaviour
{
[SerializeField] private float ClawDamage;
[SerializeField] private KilluaControl healthController;
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.name.Equals("Killua"))
{
Damage();
}
}
void Damage()
{
healthController.KilluaHealth = healthController.KilluaHealth - ClawDamage;
healthController.UpdateHealth();
}
}
Comment
Answer by PupperFish · Mar 14, 2021 at 09:14 PM
How is the variable isAttacking getting set to true?
Your answer
Follow this Question
Related Questions
Problem with enemy AI 1 Answer
Damaging enemies... 1 Answer
The name `target' does not exist in the current context 1 Answer
A way to create an invisible circle for the enemy? 4 Answers
Multiple Cars not working 1 Answer