Time.deltatime fail and how can i apply my public GameObject other;

Hi All,

I am trying to apply a smooth door open via switch (multiple doors at once with the one switch).
First problem is the swing. i have to click the door repeatedly to get it all the way.
Second problem i can seem to find a way to attach the, public GameObject other;, properly so i can use the script for multiple doors/switches with out editing.
Here’s what i have

public class DoorRotate : MonoBehaviour
{
    private float smooth = 2f;
    bool dooropen = true;
    private float open = -90f;
    private float closed = 0f;
    public GameObject other;

    void OnMouseDown()
    {
        if (dooropen == false)
        {
            transform.Rotate(new Vector3(0, open, 0) * Time.deltaTime * smooth);
        }
        else if (dooropen == true)
        {
            transform.Rotate(new Vector3(0, closed, 0) * Time.deltaTime * smooth);
        }
    }
}

Any Help is greatly appreciated

You need to update the rotation per frame. Something like this:

float toRotation;

void OnMouseDown()
{
	if (dooropen)
	{
		dooropen = false;
		toRotation = closed;
	}
	else
	{
		dooropen = true;
		toRotation = open;
	}
}

void Update()
{
	transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0f, toRotation, 0f), Time.deltaTime);
}

For 2nd problem, if you want to open/close other doors. Try a public function:

 public void SwingDoor() {
      OnMouseDown();
 }

 other.GetComponent<DoorRotate>().SwingDoor();