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

Multiple Targets Using Tags

$
0
0
I have a melee script and I want it to attack multiple target. How do I do this? Here is the script : var target : Transform; var range : int = 3; var countDown : int = 0; var coolDown : int = 2; var damage : int = 35; var attackSound : AudioClip; function Start () { if (target == null && GameObject.FindWithTag("Player")) target = GameObject.FindWithTag("Player").transform; } function Update () { if(countDown > coolDown) { countDown -= 1 * Time.deltaTime; } if(countDown < 0) { countDown = 0; } if(Input.GetButtonDown("Fire1")) { Slash(); Debug.Log(target.GetComponent(HealthLogic).currentHealth); } } function Slash() { var distance : int = Vector3.Distance(target.transform.position, transform.position); var dir = (target.transform.position - transform.position).normalized; var direction = Vector3.Dot(dir, transform.forward); if(distance <= range) { if(direction > 0) { target.GetComponent(HealthLogic).currentHealth -= damage; } } if(attackSound) { AudioSource.PlayClipAtPoint(attackSound, transform.position); } } Help me please......

Viewing all articles
Browse latest Browse all 201

Trending Articles



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