Quantcast
Channel: Questions in topic: "melee"
Viewing all articles
Browse latest Browse all 201

Hitting Multiple Enemies

$
0
0
So i got this script to target tags with enemy in them. But the problem is it only hits one enemy till it dies then goes to the next enemy with the tag enemy in it. How do i make it so that i can hit the enemies all at once if they are in reach of the collision. using UnityEngine; using System.Collections; public class PlayerAttack : MonoBehaviour { public float attackTimer; public float coolDown; private bool attack; // Use this for initialization void Start () { attackTimer = 0; coolDown = 1; } // Update is called once per frame void Update () { if(attackTimer > 0) attackTimer -= Time.deltaTime; if(attackTimer < 0) attackTimer = 0; if(Input.GetMouseButtonUp(0)){ if(attackTimer == 0){ if (attack = true){ GameObject.FindGameObjectWithTag("Enemy").GetComponent().AdjustCurrentHealth(-10); } attackTimer = coolDown; } } } void OnCollisionEnter2D(Collision2D coll) { if(coll.gameObject.tag == "Enemy") { attack = true; } } }

Viewing all articles
Browse latest Browse all 201

Trending Articles



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