C# Cheat Sheet for Unity Beginners
1. Basic Syntax
int score = 0;
float speed = 5.5f;
string playerName = "Jainam";
bool isAlive = true;
2. Functions / Methods
void Start() {
Debug.Log("Game Started!");
void Update() {
MovePlayer();
void MovePlayer() {
transform.Translate(Vector3.forward * Time.deltaTime);
3. Conditional Statements
if (score >= 10) {
Debug.Log("You Win!");
} else {
Debug.Log("Keep going!");
4. Loops
for (int i = 0; i < 5; i++) {
Debug.Log("Level: " + i);
5. Classes & Objects
public class Player {
public string name;
public int health;
public void TakeDamage(int damage) {
health -= damage;
6. Unity Special Methods
void OnTriggerEnter(Collider other) {
Debug.Log("Touched: " + other.name);
7. Accessing Components
Rigidbody rb;
void Start() {
rb = GetComponent<Rigidbody>();
rb.AddForce(Vector3.up * 5, ForceMode.Impulse);
8. Input Example
void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
Jump();
void Jump() {
Debug.Log("Jumped!");
9. Public Variables in Unity
public float moveSpeed = 5f;
void Update() {
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
10. Printing to Console
Debug.Log("Hello, Unity!");