Cheatography
https://cheatography.com
Basic keywords for Unity scripting
C#
using |
Include namespace |
class |
Define name |
// comment |
Comment: Same line |
/* comment */ |
Comment: Multiple lines |
private, protected, public |
Access specifiers |
bool |
Variable: true or false |
int |
Variable: Integer number |
float |
Variable: decimal number |
string |
Variable: Text |
null |
Empty nothing |
+ - * / % ++ -- |
Math functions |
if(condition){code}...else if(condition){code}...else {code} |
Conditional statements |
== != > < |
Relational operators |
&& || |
Logical operators |
switch(){case var: code break; default: code break;} |
Similar to if conditional statement |
Expression ? true: false; |
Similar to if |
while(condition){code} |
Loop: while |
for(init;condition;increment) {code} |
Loop: for |
do{code}while(condition) |
Loop: do...while |
int[] vars = new int[10]; |
Array wich contains 10 integers |
vars[0] = 2; |
Assign to an index of an array |
float[] vars = new int[2]{10f,20f}; |
Another array |
Methods |
public void DoSmth(){code} |
Function definition |
private void Add(int num1, int num2){code} |
Function with parameters |
private int Sum(){code return int;} |
Function with return type |
|
|
MonoBehaviour
Awake() |
Called once before everything else |
OnEnable() |
When a GameObject becomes active |
Start() |
Called once after the Awake, before the Update |
Update() |
Called every frame. Use Time.deltaTime for time relevant code |
FixedUpdate() |
Called every fixed framerate frame. Used when dealing with Rigidbody. |
Instantiate |
Creates a copy of the original object |
Destroy |
Remvoes a gameobject, or component. |
GetComponent <Type>() |
Returns the component of Type if the game object has one attached |
gameobject.transform.position |
Vector3 Position of a GameObject |
gameobject.transform.rotation |
Quaternion rotation of a GameObject |
Quaternion.Euler |
Returns the quaternion of euler rotation |
|
|
Other Components
Collider |
OnCollisionEnter(2D) |
Called when this collider/rigidbody has begun touching another rigidbody/collider |
OnCollisionExit(2D) |
Called when this collider/rigidbody has stopped touching another rigidbody/collider. |
OnTriggerEnter(2D) |
Called when this Collider other enters a trigger Collider. |
OnTriggerExit(2D) |
Called when this Collider other has stopped touching a trigger collider. |
isTrigger |
Triggers collision without physics |
Physics.Raycast |
Checks if there are colliders in a line |
RigidBody |
isKinematic |
Controls whether physics affects the rigidbody. |
useGravity |
Controls whether gravity affects this rigidbody. |
AddForce |
Applies a force of a vector to the rigidbody |
AddTorque |
Adds torque to the rigidbody |
Other |
Input.GetKeyDown("Fire1") |
Returns true or false for key |
Lerp |
Linear interpolation between values in time from 0 to 1 |
Mathf |
Math functions |
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets