- Home /
Gate Question
Created a script for when the player presses F, the objects will go down, problem is it's not working. Do you think you could tell me what's wrong with my script?
// Makes gate go down
var smooth = 2.0;
var DoorOpenAngle = 90.0;
var DoorCloseAngle = 0.0;
var open : boolean;
var enter : boolean;
//Main function
function Update (){
if(open == true){
var target = animation.Play ("Lever1");
}
if(enter == true){
if(Input.GetKeyDown("f")){
open = !open;
}
}
}
//Activate the Main function when player is near the lever
function OnTriggerEnter (other : Collider){
Debug.Log("Trigger is on");
if (other.gameObject.tag == "Player") {
Debug.Log("I am here ");
(enter) = true;
}
}
//Deactivate the Main function when player is go away from lever
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") {
Debug.Log("Trigger is on");
Debug.Log("I am here ");
(enter) = false;
}
}
Script seems to be O$$anonymous$$. But there are many things that could not work here :) Depends on scene configuration. Add some Dubug.Log at string "open = !open;". And on "var target = animation.Play ("Lever1");" Are they appear?
Answer by pixelmixer · Oct 23, 2012 at 05:24 PM
Try setting open to false in your top loop. It could be an issue with the animation.Play() getting called repeatedly.
Something like this maybe:
if(open == true){
var target = animation.Play ("Lever1");
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Unity Jet Wing Animations! Help! 1 Answer
Playing Animations? 1 Answer
Player Controller Rotation Script Help 2 Answers
Spawn Script Not Working 1 Answer