How do I check if the colliding object on OnTriggerStay is of a certain layer?
I used this and it didn’t quite work:
void OnTriggerStay(Collider Player) {
// If the player is the colliding object.
if(Player.gameObject.layer == 9) {
}
}
Any help is appreciated.
There might be a chance that it is not getting inside the OnTriggerStay method. To make sure it works well, please don’t forget to add a collider with isTrigger enabled. Also dont forget to that rigidbody has to be attached to one of the two colliding objects. If all of this is already there, try using just like Arkaid in the comments said.
int layer_index;
void Start()
{
layer_index = LayerMask.GetMask("Layer_name_you_want");
}
void OnTriggerStay(Collider Player)
{
// If the player is the colliding object.
if(Player.gameObject.layer == layer_index)
{
}
}
I recomend you that take a look about Overlap Box whit this you ll have more control in your layersMask target remember to use too DrawGizmos (see your collider limits in the scene) take care about parameters because are little bit differents.