x


Get Component

Hey I am havin a small problem, I have a script called CharacterScript in that script I am defining a PlayerState which works fine. No I wanted to create a new Object which needs the information if the Player is in PlayerState 1 or 2.

May script so far is:

var StateScript: CharacterScript;

function OnTriggerEnter (collisionInfo : Collider){

StateScript = GetComponent(CharacterScript);

if (collisionInfo.gameObject.tag == "player" && StateScript.PlayerState == 1){

Destroy(gameObject);

}

}

Somehow it does not work, seems like the object is not recieving the PlayerState... What did I do wrong ?

more ▼

asked Mar 19 '12 at 07:52 PM

deathripper gravatar image

deathripper
31 9 19 26

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

1 answer: sort voted first

Either there is no Character script on the same object as this script is on, or the tag is not "player". I would set a breakpoint in the debugger to check for it, or you can use Debug.Log to print out variables if you don't like the debugger. It might help if you post the CharacterScript code. How is PlayerState declared there?

more ▼

answered Mar 19 '12 at 08:33 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

(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

asked: Mar 19 '12 at 07:52 PM

Seen: 336 times

Last Updated: Mar 19 '12 at 08:33 PM