Reputation: 57
I am using this piece of code to see if the user is hovering over the object by the name of "townhall" hit.collider.gameObject.name == "townhall"
But, what I want is to see if the user is hovering over the children of the object by the name of "townhall"
Upvotes: 0
Views: 281
Reputation: 4591
If the parent object "townhall" has a specific script on it (ie. TownHall.cs), what you can do is check if a parent of the object in question (hit.collider) has that script. Something like this.
var townHall = hit.collider.GetComponentInParent<TownHall>();
if (townHall != null)
{
// The hit object or one of its parents has the townhall script
//
}
Be aware that the hit object itself can return the specific script when using GetComponentInParent. Just check if it is the townhall object, either by name or some other determining factor.
Upvotes: 1
Reputation: 42
Maybe this one might be helpfull, hit.collider.transform.parent.gameObject.name == "townhall"
Upvotes: 0