So I go to “play” my game and you can walk around in my little scene I’ve made… I’ve been experimenting with doors. Anyways I have the door working the way I want but it causes a very noticeable lag spike which leads me to believe that it’s not done the right way.
using UnityEngine;
using System.Collections;
public class door : MonoBehaviour
{
private bool isDoorOpen = false;
private GameObject currentDoor;
public float doorOpen = 10.0f;
public float doorClosed = 270.0f;
public bool doorLabelOpen = false;
public double xPos = Screen.width;
public double yPos = Screen.height;
// Use this for initialization
void Start()
{
}
void OnGUI()
{
if (doorLabelOpen == true)
{
GUI.Label(new Rect(Screen.width / 2, Screen.height / 1.03f, 100, 20), "Press E.");
}
}
void OnTriggerStay(Collider other)
{
Rigidbody rb = GetComponent<Rigidbody>();
if (other.gameObject.tag == "Player")
{
Debug.Log("player is here");
doorLabelOpen = true;
if (isDoorOpen == false && Input.GetKeyDown(KeyCode.E))
{
rb.transform.eulerAngles = new Vector3(transform.eulerAngles.x, doorOpen, transform.eulerAngles.z);
isDoorOpen = true;
}
else if (isDoorOpen == true && Input.GetKeyDown(KeyCode.E))
{
rb.transform.eulerAngles = new Vector3(transform.eulerAngles.x, doorClosed, transform.eulerAngles.z);
isDoorOpen = false;
}
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
doorLabelOpen = false;
}
}
}
My code is not organized all too well, so don’t mind the mess eh?
What am I doing wrong? I’m just experimenting, and I’m not expecting to be spoon fed however being pointed in the right direction would be nice!