Due to the way that I believe the OnGUI function runs it is effecting the framerate of the game. I believe the OnGUI runs every frame and within my OnGUI I have a very simple if statement
void OnGUI()
{
if(DisplayIM)
InteractionMenu();
}
Which DisplayIM gets set to true when the user presses the F key.
This is where I know the framerate issue is. (It isnt large but it is noticeable and that I do not want)
public void InteractionMenu()
{
Debug.Log("INTERACTIONS MENU");
RaycastHit hit = new RaycastHit();
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject.tag == "InteractableObject")
{
Debug.Log("Hit");
for (int i = 0; i < hit.collider.gameObject.GetComponent<InteractabeObject>().Actions.Length; i++)
{
Debug.Log("Actions Found");
GUI.Label(new Rect(10, 10+IMaSpacing, 100, 25), hit.collider.gameObject.GetComponent<InteractabeObject>().Actions*.Type);*
Debug.Log("Displaying Actions " + hit.collider.gameObject.GetComponent().Actions*.Type);*
IMaSpacing += 30;
}
}
}
}
Because the OnGUI menu is getting called every frame it ends up running this function every frame, therefore creating the labels every frame, at least whenever they are looking at the object that they pressed F on.
So my question basically is if someone could point me in the right direction. I dont need code but ideas of how I should solve this. At this point I am at a mental block and any help is very appreciated.