I have a ship with multiple pieces of wood like a real ship. each piece has a collider and the same script:
public void ApplyDamage(int damageTotal)
{
health -= damageTotal;
Debug.Log("Damage " + damageTotal + " was applied");
Destroy(gameObject);
}
My goal is to check which piece got hit with a cannonball using send message or any other way. how do i get it to send message to the right piece.
Cannonball script:
void OnCollisionEnter(Collision hit)
{
Debug.Log("Collision Detected");
if (hit.gameObject.tag == "ShipPlate")
{
hit.gameObject.SendMessage("ApplyDamage", 5); // send the message to its owner
Debug.Log("aaa");
Destroy(gameObject);
}
}