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

Can't put Sendmessage to work.

$
0
0
hey guys, I have been trying to make a melee system where a sphereoverlap will tell me if there is any target in range, and if he is in range I'll test the distance as the sphereoverlap is not 100% accurate and if the distance checks out I'll send a message to the enemy to run the "DamageDeal" function, but for some reason it doesn't identify a receiver and never send the message. Here's a bit of the code for melee that is supposed to send the message: var collisions : Collider[] = Physics.OverlapSphere(transform.position, range); for (var hit : Collider in collisions) { if (hit && hit.tag == "enemy") { dist = Vector3.Distance(hit.transform.position, transform.position); Debug.Log(dist); Debug.Log("Step 2"); if (dist <= range) { Debug.Log("Step 3"); hit.gameObject.SendMessage("DamageDeal", dmg, SendMessageOptions.DontRequireReceiver); } } and here's the code on the enemy: var currentHealth : int = 0; var maxHealth : int = 100; function Star() { currentHealth = maxHealth; } function Update () { if ( currentHealth <= 0) Destroy(gameObject); } function DamageDeal (dmg : int) { Debug.Log("Step 4"); currentHealth -= dmg; } What am i doing wrong?

Viewing all articles
Browse latest Browse all 201

Trending Articles



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