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

avatar image

Ouija
123 21 925 48

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

3 answers: sort voted first
more ▼

answered Aug 14, 2013 at 05:45 PM

avatar image

rednax20
476 35 51 70

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

avatar image

SubatomicHero
1.4k 7 11 17

(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

avatar image

crypt724
17 4 9 10

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:

x105
x67
x51

asked: Aug 14, 2013 at 05:41 PM

Seen: 606 times

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