Hi, I am making a game which requires doors to be opened frequently. I have written the code below, however, when I first click the door, it polays the “DoorClose” animation when the “DoorOpen” animation should be playing. A solution would be very helpful.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorController : MonoBehaviour
{
private Animation anim;
private bool DoorIsClosed;
void Start()
{
DoorIsClosed = true;
anim = gameObject.GetComponent<Animation>();
}
void OnMouseDown()
{
if (DoorIsClosed == true)
{
anim.Play("DoorOpen");
DoorIsClosed = false;
}
if (DoorIsClosed == false)
{
anim.Play("DoorClose");
DoorIsClosed = true;
}
}
}