I’m trying to use SendMessage to tell an object that it has been hit by a ray. Basically, I have two attacks. I have a short hit and a long hit, each need to do different damage. How do I send the amount of damage that it needs to apply to the receiver?
Lets say your receiver have a Damage function with a float parameter
void Damage(float damageValue){
hp -= damangeValue;
}
Then on the other side, when the raycast hit the object then Call the SendMessage function
float damangeValue = 10f;
RaycastHit hit;
if(Physics.Raycast(gun.position, gun.forward, out hit, rayDistance)){
hit.collider.gameObject.SendMessage("Damage", damangeValue);
}