Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Hey, im trying to include a cooldown for my enemy attack. At the moment when the player enters the trigger the enemy attacks really fast and doesnt stop . heres my script, can anybody help?

$
0
0
using UnityEngine; using System.Collections; public class EnemyTrigger : MonoBehaviour { public float weaponDamage; private float AttackTime; private float attackcd = 20; private bool canAttack = false; public GameObject hitFX; public Collider2D attackTrigger; float nextattackTime; Animator enemyattackAnim; // Use this for initialization void Start () { enemyattackAnim = GetComponentInParent (); attackTrigger.enabled = true; } // Update is called once per frame void Update () { attackTrigger.enabled = true; AttackTime = attackcd; { } } void OnTriggerStay2D(Collider2D other){ if (other.gameObject.layer == LayerMask.NameToLayer ("Attackable")) { enemyattackAnim.SetTrigger ("enemyattack"); AttackTime = attackcd; PlayerHealth1 hurtPlayer = other.gameObject.GetComponent (); hurtPlayer.addDamage (weaponDamage);{ Instantiate (hitFX, transform.position, transform.rotation); } } } private void Swordattack() { AttackTime += Time.deltaTime; if (AttackTime >= attackcd) { canAttack = true; AttackTime = 0; } if (canAttack) { canAttack = false; enemyattackAnim.SetTrigger ("enemyattack"); } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>