it’s working but it never back to idle it is continuosly… am struggling with this…
this s my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// Attack with ranged weapon
///
public class AttackRanged : MonoBehaviour, IAttack
{
// Damage amount
public int damage = 1;
// Cooldown between attacks
public float cooldown = 1f;
// Prefab for arrows
public GameObject arrowPrefab;
// From this position arrows will fired
public Transform firePoint;
// Animation controller for this AI
private Animator anim;
// Counter for cooldown calculation
private float cooldownCounter;
///
/// Awake this instance.
///
void Awake()
{
anim = GetComponentInParent();
cooldownCounter = cooldown;
Debug.Assert(arrowPrefab && firePoint, “Wrong initial parameters”);
//gameObject.GetComponent().offset = new Vector2(newX, newY);
}
///
/// Update this instance.
///
void FixedUpdate()
{
if (cooldownCounter < cooldown)
{
cooldownCounter += Time.fixedDeltaTime;
}
}
///
/// Attack the specified target if cooldown expired
///
/// Target.
public void Attack(Transform target)
{
if (cooldownCounter >= cooldown)
{
cooldownCounter = 0f;
Fire(target);
}
}
/*void OnCollisionEnter2D(Collision2D col)
{
if(col.gameObject.name == “BowmanL1”)
{
Debug.Log (“aaaa”);
anim.SetTrigger(“shootright”);
}
}*/
///
/// Make ranged attack
///
/// Target.
public void Fire(Transform target)
{
if (target != null) {
// Create arrow
GameObject arrow = Instantiate (arrowPrefab, firePoint.position, firePoint.rotation);
IBullet bullet = arrow.GetComponent ();
bullet.SetDamage (damage);
bullet.Fire (target);
if (target.position.x < transform.position.x) {
anim.SetBool (“shootleft”, true);
Debug.Log (“left”);
} else if (target.position.x > transform.position.x) {
anim.SetBool (“shootright”, true);
Debug.Log (“right”);
}
else
{
anim.SetTrigger (“idle”);
Debug.Log (“idle”);
}
}
}
}