x


Cannot stop character movement upon trigger

I want to make it so when the player walks over this trigger it stops movement but still lets them move the camera

function OnTriggerEnter(other : Collider) {

GetComponent("CharacterMotor").enabled = false;

}

Thats what i've got but it comes up with the error "Object reference not set to an instance of an object"

Any help would be much appreciated

more ▼

asked Apr 28 '12 at 04:41 PM

TheoryFighter gravatar image

TheoryFighter
1 1 1 1

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

2 answers: sort voted first

has to be:

GetComponent(CharacterMotor).enabled = false;

without the ""

more ▼

answered Apr 28 '12 at 05:08 PM

Hybris gravatar image

Hybris
415 5 8 10

Both are fine.

Apr 28 '12 at 05:49 PM fafase

Type is better than string though lol

Apr 28 '12 at 05:50 PM Lo0NuhtiK

Indeed.I just punched my screen reading the "has to be:" and my girlfriend behind told me "Don't let him get away with it!!". But yes, without "" is better. So for serious information, both are working but without the "" is more efficient.

Apr 28 '12 at 05:54 PM fafase
(comments are locked)
10|3000 characters needed characters left
function OnTriggerEnter(other : Collider){
   if(other.gameObject.CompareTag("Player")){
      var charMotor : CharacterMotor ;
      charMotor = other.GetComponent(CharacterMotor) ;
      charMotor.enabled = false ;
   }
}

...or just using [ other.GetComponent(CharacterMotor).enabled = false ;] would probably work also... what I think you're missing though, is simply the 'other.' part since I'm assuming your script is on another object and you need to get the character motor script off of the object that enters it (what your code does at the moment, is try to get CharacterMotor from the object which this script is attached to, not the object that enters it)

more ▼

answered Apr 28 '12 at 05:08 PM

Lo0NuhtiK gravatar image

Lo0NuhtiK
3.5k 1 9 39

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

x1362
x1040
x980
x141

asked: Apr 28 '12 at 04:41 PM

Seen: 812 times

Last Updated: Apr 28 '12 at 05:58 PM