Problem with script placement.

hello again...i have a problem.

right now, i have make a code for pulling a switch. it work fine doesnt have any error.

but the problem is i cannot put the script inside a game object for example i want to put the script inside my "switch". if i put it inside the "switch" nothing happen..the script wont work.

but if i put my script inside a character the script work fine..

here is the script:

var leverIsPull = false;

function Update() { print(leverIsPull); }

function OnControllerColliderHit (hit : ControllerColliderHit) { // I change the name between "Player" and "Pullswitch" // "Player" = if i put the script inside the game object // "Pullswitch" = if i put the script inside the character if(hit.gameObject.tag == "pullswitch") { var pulling = gameObject.FindWithTag("pullswitch"); if(Input.GetButton ("Button A")) { pulling.animation.Play("pull"); leverIsPull = false; }

var pulling2 = gameObject.FindWithTag("pillar"); if(leverIsPull) { yield WaitForSeconds (2); pulling2.animation.Play ("trap"); } }

}

Your call to OnControllerColliderHit() is specific to the character controller being on the object. If you wish to use the script on more generic objects, use the OnTriggerEnter() and OnCollisionEnter() functions. Those two functions will work with regular colliders, in either Trigger mode on or off respectively.

Ive try and change it into OnCollisionEnter()..but i dont have any feedback with the script.

heres the code that Ive change:

var leverIsPull = false;

function Update() { print(leverIsPull); }

function OnCollisionEnter (hit : Collision) { if(hit.gameObject.tag == "Player") { var pulling = gameObject.FindWithTag("pullswitch"); if(Input.GetButton ("Button A")) { pulling.animation.Play("pull"); leverIsPull = false; }

var pulling2 = gameObject.FindWithTag("pillar"); if(leverIsPull) { yield WaitForSeconds (2); pulling2.animation.Play ("trap"); } }

}

am I doing the wright thing?