x


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 :( 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. :)

more ▼

asked Aug 14, 2013 at 05:41 PM

Ouija gravatar image

Ouija
68 19 918 31

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first
more ▼

answered Aug 14, 2013 at 05:45 PM

rednax20 gravatar image

rednax20
450 22 40 55

Thanks I'll give them a look!

Aug 14, 2013 at 06:06 PM Ouija

I found this line in another question, think it would help? I suck at writing code lol seems like its on the right track though?

GetComponent("SmallBoxScript").enabled = false;

Aug 14, 2013 at 06:14 PM Ouija
(comments are locked)
10|3000 characters needed characters left

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
more ▼

answered Aug 14, 2013 at 05:46 PM

SubatomicHero gravatar image

SubatomicHero
1.4k 4 8 14

(comments are locked)
10|3000 characters needed characters left

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);
}
more ▼

answered Aug 14, 2013 at 06:52 PM

crypt724 gravatar image

crypt724
7 3 7 9

shutoff.js(5,35): BCE0019: 'enabled' is not a member of 'UnityEngine.Component'

hmmmmmmmm? lol

Aug 14, 2013 at 10:36 PM Ouija
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4692
x95
x58
x47

asked: Aug 14, 2013 at 05:41 PM

Seen: 470 times

Last Updated: Aug 14, 2013 at 10:36 PM