x


Disable a script on collision

Hi, I'm trying to disable the ThirdPersonController script on my player on Collision so that he attaches himself onto a sphere and then the NormalWalking Script takes over so he floats around it like a moon's gravity. I'd like to be able to disable the ThirdPersonController on collision with the moon and enable the script when he collides with something else but I think I've done something wrong. Can anybody help me out?

function OnCollisionEnter (other : Collision) {

if (other.name == "world") { GameObject.ThirdPersonController.enabled=false; print("off"); }

if (other.name != "world") { GameObject.ThirdPersonController.enabled=true;

print("on"); }

}

more ▼

asked Nov 25 '11 at 10:42 PM

cystemic gravatar image

cystemic
46 2 4 5

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

2 answers: sort voted first

Well, first you should always say what you are trying to do(as you are) but also mention what happens instead of the intended result. Like what error do you get and so on.

In this case I am going to guess you are getting an error because you are using GameObject instead of gameObject.

more ▼

answered Nov 25 '11 at 11:03 PM

Anxowtf gravatar image

Anxowtf
1.6k 22 27 37

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

Sorry for being vague but I'm not getting any errors at all. The script just won't disable and my character falls to his death when the two collide and I walk off the edge.

more ▼

answered Nov 25 '11 at 11:10 PM

cystemic gravatar image

cystemic
46 2 4 5

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

x3328
x2492
x1951
x460
x215

asked: Nov 25 '11 at 10:42 PM

Seen: 1048 times

Last Updated: Nov 25 '11 at 11:10 PM