Hello there,
I need help due to my door script problems. Opening doors with E key button works definitely fine except first try. That means that when i launch game mode, go to the collider and press E nothing opens (but audio is played). You have to double tap the button to open doors for first time, but after that everything works normal (one tap opening door). Any suggestions ?
Script :
{
public bool open;
public bool close;
public bool inTrigger;
public Transform doorHinge;
public AudioSource audio;
void Start ()
{
}
void OnTriggerEnter(Collider other)
{
inTrigger = true;
}
void OnTriggerExit(Collider other)
{
inTrigger = false;
}
void Update()
{
if (inTrigger)
{
if (close)
{
if (Input.GetKeyDown(KeyCode.E))
{
open = true;
close = false;
audio.Play ();
}
}
else
{
if (Input.GetKeyDown(KeyCode.E))
{
close = true;
open = false;
audio.Play ();
}
}
}
if (open)
{
var newRot = Quaternion.RotateTowards(doorHinge.rotation, Quaternion.Euler(0.0f, 90.0f, 0.0f), Time.deltaTime * 250);
doorHinge.rotation = newRot;
}
else
{
var newRot = Quaternion.RotateTowards(doorHinge.rotation, Quaternion.Euler(0.0f, 0.0f, 0.0f), Time.deltaTime * 250);
doorHinge.rotation = newRot;
}
}
void OnGUI()
{
if (inTrigger)
{
if (open)
{
GUI.Box(new Rect(0, 0, 400, 50), "Press E to close");
}
else
{
GUI.Box(new Rect(0, 0, 400, 50), "Press E to open");
}
}
}
}