- Home /
The question is answered, right answer was accepted
How to fix my door from being destroyed?
Hello!!! I have a problem with two scripts that I don't know how to fix and I have tried different ways, but still nothing. I have a door that you can open when you click the mouse. I also have a code to pick Up pages (5 in total) whenever I click the mouse. In both script I use the OnTriggerStay function to perform the action and in the pages it destroys them when I pick them up. The problem is the door, it destroys the door when I click it, and I want it to play an open Door animation.
Pages Script:
var paper = 0;
var hasPapers = false;
function OnTriggerStay (collision : Collider){
if (Input.GetMouseButton(0)){
paper += 1;
Destroy(collision.gameObject);
audio.Play();
}
}
function Update(){
if (paper == 5){
hasPapers = true;
}
}
function OnTriggerEnter(collision : Collider){
if (collision.tag == "Exit"){
if (!hasPapers){
Debug.Log("Need Pappers");
}
if (hasPapers){
Application.LoadLevel("Credits");
}
}
}
function OnGUI (){
GUI.Label (new Rect(Screen.width - 100,40,100,100), paper + " / 5 Pages" );
}
Door Script:
function OnTriggerStay (collision : Collider) {
if (Input.GetMouseButton(0)){
animation.Play("DoorOpen");
}
}
Thanks for the Help and I hope you understood my question.
On line 7 you are actually destroying the object: Destroy(collision.gameObject); try changing this for you open door animation.
Follow this Question
Related Questions
Multi Switch Door 4 Answers
trigger animation problems 2 Answers
Can't click gameobject when over another trigger? 1 Answer
Import and launch a animation (with trigger) 2 Answers
Doors open when you look at it 3 Answers