I have a cylinder with a hole.
The character can enter the hole.
But now i want to trigger something once the character is inside the hold inside the cylinder.
In the screenshot on the left it’s the Hierarchy part of the Cylinder.
Then the Cylinder part in the scene view.
Then the cylinder inspector.
And on the right the BezierCircle inspector.
Now the BezierCircle is the hole the character can walk in and out.
And the BezierCircle is where i want to detect where the character enter/leave it.
Not collide with it but enter it.
The BezierCircle have a collider component Mesh Collider but i unchecked it not to use it since if i will use this collider the character will not be able to enter the hole(BezierCircle).
The question is how by script i can detect when the character is inside/ouside the BezierCircle ?
The simplest way I can see you doing this is to add a box collider to your object that fills the entrance to your circle in the area you want to detect. If you tick the ‘is trigger’ box on the collider, it will mean objects can pass through it freely, but you can use it to detect things instead.
If the player has a rigidbody attached (which if you’re using the default third-person controller I believe it does), then you can use the ‘OnTriggerEnter()’ method to run code whenever something with a rigidbody enters the collider area. So for example:
bool detected = false;
OnTriggerEnter (Collider other)
{
if (other.name == "Player")
{
detected = true;
}
}
OnTriggerExit (Collider other)
{
if (other.name == "Player")
{
detected = false;
}
}
This is a simple example of detecting something has entered the collider’s range and doing something, and then doing something else when it leaves. In this case, OnTriggerEnter will run when an object enters, check what the name of the object is, and if it is Player then it will set detected to true. When an object leaves, OnTriggerExit runs and checks if the thing leaving is named Player. If it is, it sets detected to false.
Whatever script you write that in would then need to be attached to the object that has the collider attached to fill in the doorway. I hope that gives you a good idea of where to start to achieve what it is you need 