Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
error CS0119: 'FramePerSecond.On_GUI()' is a method, which is not valid in the given context

What I have tried:

C#
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine.UI;
using UnityEngine;

public class FramePerSecond : MonoBehaviour
{
    Rect fpsRect;
    GUIStyle style;

    void Start ()
    {
        fpsRect = new Rect(100, 100, 400, 100);
        style = new GUIStyle();
        style.fontSize = 30;
    }

    void Update()
    {

    }

    void OnGUI()
    {
        float fps = 1 / Time.deltaTime;
        OnGUI.Label(fpsRect, "FPS: " + fps);
    }
}
Posted
Updated 27-Oct-20 1:03am
v2

C#
void OnGUI()
{
    float fps = 1 / Time.deltaTime;
    OnGUI.Label(fpsRect, "FPS: " + fps);
}

You are trying to use OnGUI as a property reference inside a method that you have named OnGUI, which does not make sense.
 
Share this answer
 
v2
The class that exposes the Label method is called just "GUI", not "OnGUI".

C#
void OnGUI()
{
    float fps = 1 / Time.deltaTime;
    GUI.Label(fpsRect, "FPS: " + fps);
}


"OnGUI" is the name of a function that is called when the GUI event fires.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900