Hi,
I have a door that has open/close animations and the script below -
My problem is, if I duplicate the door, then in the game, if I open ‘Door01’ it’s fine, however when I go to open the other door as well, it plays the close animation (on the right door bear in mind).
It looks like my bools are getting caught up somehow.
Help would be very appreciated thanks!
public AudioClip[] doorSounds;
static bool doorOpen = false;
static bool doorMoving = false;
private static GameObject thisDoor;
IEnumerator openDoor(){
doorMoving = true;
thisDoor.animation.Play("door_Open");
thisDoor.audio.PlayOneShot (doorSounds [0]);
yield return new WaitForSeconds (thisDoor.animation["door_Open"].length);
doorOpen = true;
doorMoving = false;
}
IEnumerator closeDoor(){
doorMoving = true;
thisDoor.animation.Play("door_Closed");
yield return new WaitForSeconds (thisDoor.animation["door_Closed"].length);
thisDoor.audio.PlayOneShot (doorSounds [1]);
doorMoving = false;
doorOpen = false;
}
void Update () {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if(Input.GetButtonDown("Fire1") ){
if(Physics.Raycast(ray, out hit) && (hit.collider.gameObject == hit.transform.gameObject.Equals(gameObject) )){
thisDoor = hit.collider.gameObject;
if(doorMoving == false){
if(doorOpen == false){
StartCoroutine("openDoor");
} else {
StartCoroutine("closeDoor");
}
}
}
}
}