Can't put Sendmessage to work.

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?

dmg is an int? You don't show it here. If it isnt then it wont work.

1 Answer

1

so, i was being retarded and put the tag on the wrong cube --’ sorry all!

This is embarrassing…

Happens :0)