Hi
I have a cannonball with a collider attached to it. That cannonball collides with different objects, some of the objects have a script attached “Health_Script”, and other objects is just colliders. I want (in a script attached to the cannonball) to check if the colliding object has a “Health_Script” attached.
The following code, works but brings the error message “NullReferenceException” when the colliding object either doesn’t have a rigidbody or a “Health_Script” attached.
My question is: Is it wrong that code in some cases brings error messages even though it’s working? In that case, what is the proper way to check if an object has a specific script attached to it?