-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add simple FPS Counter #18
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work I'm glad for your contribution! But I have a few comments to make it better.
Assets/Scripts/CubeType.cs
Outdated
private Rigidbody _rb; | ||
public CubeTypes type; | ||
|
||
void Awake() { | ||
_rb = GetComponent<Rigidbody>(); | ||
_rb.interpolation = RigidbodyInterpolation.Interpolate; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I'd revert those changes just because using this rigidbody's interpolation type is even worse in our case. It's fully clipping through everything. I created an issue for this #19 and will be worked on later, because it's a bit more complicated problem.
m_Script: {fileID: 11500000, guid: ddeaeffe06d8ff842acfd08df3bc544f, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
fpsCounterText: {fileID: 0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fpsCounterText
of FpsUI
is not assigned so we get a NullReferenceException.
Assets/Scripts/UI/FpsUI.cs
Outdated
using UnityEngine; | ||
using TMPro; | ||
public class FpsUI : MonoBehaviour { | ||
public TextMeshProUGUI fpsCounterText; | ||
float fpsCounter; | ||
float refreshTime = 0.5f; | ||
void Update() { | ||
fpsCounter = (int)(1f / Time.unscaledDeltaTime); | ||
if (Time.time > refreshTime) { | ||
fpsCounterText.text = fpsCounter.ToString(); | ||
refreshTime += 0.5f; | ||
} | ||
|
||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First things first
- We are using tabs instead of spaces for indentation, to change your default indentation method please see your editor config.
- Use
private
keyword for private members just for explicitness and use_
prefix for private variables names. - Blank lines are messy. Under namespaces should be empty line, before method definition, at the end is some unnecessary space and file should end with a new line. You can see other scripts to get overall style convention, which is about to get more defined in near future.
Assets/Scripts/UI/FpsUI.cs
Outdated
fpsCounter = (int)(1f / Time.unscaledDeltaTime); | ||
if (Time.time > refreshTime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can put this calculation into this condition so we don't lose this 1 CPU cycle :P
Assets/Scripts/UI/FpsUI.cs
Outdated
void Update() { | ||
fpsCounter = (int)(1f / Time.unscaledDeltaTime); | ||
if (Time.time > refreshTime) { | ||
fpsCounterText.text = fpsCounter.ToString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simply add + " FPS"
at the end of this line, because for now it's a strange number on our screen and we don't know what it is.
Assets/Scripts/UI/FpsUI.cs
Outdated
fpsCounter = (int)(1f / Time.unscaledDeltaTime); | ||
if (Time.time > refreshTime) { | ||
fpsCounterText.text = fpsCounter.ToString(); | ||
refreshTime += 0.5f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this 0.5f
mean? Where is it from?
Do your best to omit magic numbers.
No description provided.