- Home /
Question by
PolymathicIndustries · Apr 28 at 05:11 PM ·
buttonspeedbooleanienumeratorcondition
Why is door opening so fast with boolean condition?
I have the following script that I have modified to allow a door to open upon clicking and then for a button to enter that room to show seconds later. The whole thing works, but for some reason the door opens much faster now that I added in a boolean condition to the DoorOpening function. Why would this change speed of the door?
// Smoothly open a door
public float doorOpenAngle = 90.0f; //Set either positive or negative number to open the door inwards or outwards
public float openSpeed = 2.0f; //Increasing this value will make the door open faster
bool open = false;
bool enter = false;
float defaultRotationAngle;
float currentRotationAngle;
float openTime = 0;
public float waitTime = 2;
public GameObject doorButton;
bool endNow = false;
void Start()
{
defaultRotationAngle = transform.localEulerAngles.y;
currentRotationAngle = transform.localEulerAngles.y;
enter = true;
doorButton.gameObject.SetActive(false);
}
// Main function
void Update()
{
if (openTime < 1)
{
openTime += Time.deltaTime * openSpeed;
}
transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, Mathf.LerpAngle(currentRotationAngle, defaultRotationAngle + (open ? doorOpenAngle : 0), openTime), transform.localEulerAngles.z);
}
public void DoorOpening()
{
if (endNow == false)
{
endNow = true;
if (openTime < 1)
{
openTime += Time.deltaTime * openSpeed;
}
transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, Mathf.LerpAngle(currentRotationAngle, defaultRotationAngle + (open ? doorOpenAngle : 0), openTime), transform.localEulerAngles.z);
open = !open;
currentRotationAngle = transform.localEulerAngles.z;
openTime = 0;
}
}
private void OnMouseDown()
{
DoorOpening();
StartCoroutine(WaitForButton());
}
IEnumerator WaitForButton()
{
yield return new WaitForSeconds(waitTime);
doorButton.gameObject.SetActive(true);
}
Why would this door open so quickly, even when I drastically reduce the openSpeed to 0.25 even?
Comment