i am trying a ball enter into cube for cartain times, after the ball come out from cube it wants to be enable automatically?
i have used this code for disable...
function OnTriggerEnter()
{
collider.isTrigger= true;
}
The first thing you have to understand about colliders is that isTrigger controls the operation of the collider itseld. Meaning - will it be a physical collider that receives collision events (OnCollisionEnter(), OnCollisionExit(), OnColliderStay()) or a trigger collider that receives trigger events (OnTriggerEnter(), OnTrigerExit(), OnTriggerStay()), but is ignored by the physics engine.
I can't understand exactly what you want to be enabled or disabled...
The code you wrote will work only if the collider is already a trigger collider, which makes the "collide.isTrigger = true" to be redundant (unless I'm missing something in your setup).
Can you try and explain in detail what you want to achieve? Do you want object to enter the box and not leave? Do you want the box to not let other objects in? How then do you put them in?
What should this do?
The basic usage of triggers is to use OnTriggerEnter() to register something entered the box, and OnTriggerExit() when it leaves the box. You can use the "collider" parameter to check if the object entering was the same one leaving.
If you want to run some code WHILE the object is inside, you can run it at the OnTriggerStay() method. It will only run while the object is inside. When it will leave the trigger collider, the code will not run.
I found the correct answer to be; gameObject.collider.enabled = true/false; GameObject coughed back an error.
– Rick74