- Home /
This question was
closed May 01, 2013 at 09:06 AM by
Fattie for the following reason:
Duplicate Question
Question by
AfricanMoney · May 01, 2013 at 07:31 AM ·
javascriptanimationsdoor
Door opening and closing script not working
I have this script attached to my door:
var InRange : boolean = false;
var PressA : boolean = false;
var ThePlayer : Transform;
var DoorClosed : boolean = true;
var DoorOpen : boolean = false;
function Start ()
{
}
function Update ()
{
var distance : float = Vector3.Distance (ThePlayer.transform.position, transform.position);
if (distance < 1.5f)
{
InRange = true;
PressA = true;
}
else
{
InRange = false;
PressA = false;
}
}
function OnGUI ()
{
if (InRange == true && PressA == true)
{
GUI.Box (new Rect (460, 495, 40, 25), "Open");
if(InRange == true && Input.GetButtonDown ("Fire1") && DoorClosed == true)
{
animation.Play ("OpenDoor");
DoorOpen = true;
DoorClosed = false;
}
else if (InRange == true && Input.GetButtonDown ("Fire1") && DoorOpen == true)
{
animation.Play ("CloseDoor");
DoorClosed = true;
DoorOpen = false;
}
}
}
I have applied the two animations to the door and I have placed the player is the variable "ThePlayer", but when I go to open it the door jumps open without the animation and then plays the closing door animation. What am I doing wrong?
P.S Im using JavaScript
Comment
Best Answer
Answer by MrSteve1 · May 01, 2013 at 08:22 AM
this
if(InRange == true && Input.GetButtonDown ("Fire1") && DoorClosed == true)
{
animation.Play ("OpenDoor");
DoorOpen = true;
DoorClosed = false;
}
else if (InRange == true && Input.GetButtonDown ("Fire1") && DoorOpen == true)
{
animation.Play ("CloseDoor");
DoorClosed = true;
DoorOpen = false;
}
needs to be Update() not OnGUI()
Thanks mate it works again. What a stupid mistake on my behave :)
Follow this Question
Related Questions
Open doors with key & sound 1 Answer
Door to Next Level HELP! 2 Answers
Animation not playing with animation.Play 1 Answer
Sound effect on right click 1 Answer