Turn on/off Script

There is a large box with a small box inside. The small box has a script on it.
How would you turn the small box script OFF when it passes through the larger box? and then turn back ON if you go back inside the larger box?

Edit: Leaving cryptic answers only confuse me as a beginner :frowning: Anyone willing to write the full answer with it somewhat explained? I’d love to learn to write my own but I always get broken code that doesn’t make sense to me just yet. :slight_smile:

Try looking into OnTrigger Enter/Stay/Exit.

Quishtay all the way™

You don’t turn off the script you deactivate the small cube gameobject when the collision between the two cubes occurs and then reactivate the cube once the collision has stopped.

gameObject.SetActive (false); //deactivate

gameObject.SetActive (true); //activate

try this you want to put this on your big box make sure you set the big box as trigger and dont forget to assign you gameobject to smallbox

Var smallbox : GameObject;
    
    function OnTriggerEnter (){
    
    smallbox.SetActive (false);
}

function OnTriggerExit(){

smallbox.SetActive (true);
}