I am trying to open doors by clicking the left mouse button.
There are 4 doors in my scene. Right now I have managed to write codes for 2 of the doors. Now the problem when click on one door (or anywhere on the screen), the other door also opens simultaneaously. What I want is that I want one door to open and when I click on the next door the previous door should close automatically. I am attaching the scripts for the 2 doors that I have written. PS: I am not much of a coder. So any help would be appreciated. Thanks!
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class AnimateDoorA : MonoBehaviour { public Animator anim; public Animator anim1; public AudioSource sound; // Start is called before the first frame update void Start() { anim = GetComponent(); anim1 = GetComponent(); }
// Update is called once per frame
void Update()
{
if(Input.GetMouseButton(0))
{
anim.Play("DoorAnimationA");
anim1.Play("A Appearing");
sound.Play();
}
}
}
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class AnimateDoorB : MonoBehaviour { public Animator animB; public Animator animB1; public AudioSource soundB; // Start is called before the first frame update void Start() { animB = GetComponent(); animB1 = GetComponent(); }
// Update is called once per frame
void Update()
{
if(Input.GetMouseButton(0))
{
animB.Play("B Appearing");
animB1.Play("B AppearingNot Door");
soundB.Play();
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613045649im_/https://answers.unity.com/themes/thub/images/avi.jpg)