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

Need help with my melee system and arrays

$
0
0
Hey guys, I'm still fairly new to programming and this problem has been giving me a major headache. Hopefully one of you guys can help me out. So I currently have a melee system working (using this guy's tutorials:https://www.youtube.com/watch?v=fxSM_INrmF8). The problem is that the weapon only focuses on one enemy of the same tag -- meaning it only inflicts damage to one instance of that enemy. Instead, I want it to do damage to multiple enemies of different tags (at most 3 tags) if they're in front of the player. I know I'm going to have to implement a list, or array, to hold my enemies, but I'm not sure how. Any help would be great, thanks! public class Melee : MonoBehaviour { public float lightAtkDmg, heavyAtkDmg; public GameObject target; private float heavyDistance; private float lightDistance; private float deflectionDistance; bool isAttacking = false; // Use this for initialization void Start () { //target = } // Update is called once per frame void Update () { Debug.DrawLine (target.transform.position, transform.position, Color.yellow); } public void heavyAttack(){ isAttacking = true; heavyDistance = Vector3.Distance (target.transform.position, transform.position); Vector3 Dir = (target.transform.position - transform.position).normalized; float Direction = Vector3.Dot (Dir, transform.forward); Debug.Log (Direction); Debug.Log (heavyDistance); if (target.gameObject.tag == "Enemy" && heavyDistance < 3) { if(Direction>0){ Debug.Log ("Hit Enemy_Charger w/Heavy"); target.GetComponent ().TakeDamage (heavyAtkDmg); } } if (target.gameObject.tag == "Destructible" && heavyDistance < 2) { if(Direction>0){ Debug.Log ("Hit EDestructible w/Heavy"); target.GetComponent ().TakeDamage (heavyAtkDmg); } } if (target.gameObject.tag == "Magic" && heavyDistance < 2) { if (Direction >0 & heavyDistance >1.8){ Debug.Log("magic deflected w/heavy"); } } isAttacking = false; } public void lightAttack(){ Debug.Log ("perform Light Attack"); isAttacking = true; Vector3 Dir = (target.transform.position - transform.position).normalized; float Direction = Vector3.Dot (Dir, transform.forward); lightDistance = Vector3.Distance (target.transform.position, transform.position); Debug.Log ("Light Distance" + lightDistance); //Debug.Log (Direction); if (target.gameObject.tag == "Enemy" && lightDistance < 1) { if (Direction > 0){ Debug.Log ("Hit Enemy w/light"); target.GetComponent ().TakeDamage (lightAtkDmg); } } if (target.gameObject.tag == "Destructible" && lightDistance < 1) { if (Direction > 0){ Debug.Log ("Hit Destructible w/light"); target.GetComponent ().TakeDamage (lightAtkDmg); } } if (target.gameObject.tag == "Magic" && lightDistance < 15 && lightDistance > 1) { if (Direction > 0) { Debug.Log ("magic deflected w/light"); } } isAttacking = false; } }

Viewing all articles
Browse latest Browse all 201

Trending Articles



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