You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ideally you would not want to run GetComponent every frame in Update; especially multiple in times. This will (probably) increase fps (since unity does not need to look it up multiple times before the next frame) and cpu load.
Re-Assignment
The code snippet below includes two IF checks; two assignments and two re-assignments
onGround=CheckGround();//Different acceleration values for ground and airfloatcurAccel=accel;if(!onGround)curAccel=airAccel;//Ground speedfloatcurMaxSpeed=maxSpeed;//Air speedif(!onGround)curMaxSpeed=maxAirSpeed;
It could be refactored to include only two IF checks and two assignments (and its concise)
These are just a few suggestions to make your game more accessible to those on lower spec hardware :)
Remember, optimization is easier to do when you write code rather than refactor it later on
The text was updated successfully, but these errors were encountered:
GetComponent
Unity's
GetComponent()
function is very expensive. You should cache the Rigidbody as such:Ideally you would not want to run
GetComponent
every frame inUpdate
; especially multiple in times. This will (probably) increase fps (since unity does not need to look it up multiple times before the next frame) and cpu load.Re-Assignment
The code snippet below includes two IF checks; two assignments and two re-assignments
It could be refactored to include only two IF checks and two assignments (and its concise)
These are just a few suggestions to make your game more accessible to those on lower spec hardware :)
Remember, optimization is easier to do when you write code rather than refactor it later on
The text was updated successfully, but these errors were encountered: