🔷 Unity — Complete Developer Guide

C# scripting, Android build, AdMob integration, and publishing — step by step

Why Unity for Game Development?

Unity is the world's most used game engine — powering over 50% of all mobile games. It supports 2D and 3D development, exports to Android, iOS, PC, and WebGL, and has the largest developer community. For Pakistani developers, Unity offers the best combination of job opportunities, tutorials, and mobile game publishing support.

💡 Unity Personal is 100% free for individuals and companies earning under $200,000/year. Full engine, no watermarks, no feature restrictions.


Unity Interface — Key Panels

Scene View

Your level editor. Place, move, rotate, and scale objects here. Use W (move), E (rotate), R (scale) shortcuts. Hold right-click and WASD to fly around the scene.

Game View

Shows exactly what the player sees. Press the Play button (▶) to test your game instantly. Always test in Game View before building — it shows the correct camera and UI scaling.

Hierarchy

Lists every GameObject in the current scene. Parent-child relationships shown here. Drag a GameObject onto another to make it a child — it will move with the parent.

Inspector

Shows all components on the selected GameObject. Change Transform (position, rotation, scale), add components (Rigidbody, Collider, scripts), and edit script variables here.

Project Window

Your file browser inside Unity. All assets (scripts, images, audio, prefabs) live here. Organize into folders — Assets/Scripts, Assets/Sprites, Assets/Audio is a good starting structure.

Console

Shows Debug.Log() messages, warnings, and errors. Always check the Console when your game behaves unexpectedly. Click an error to jump to the line of code that caused it.


C# Scripting Fundamentals

Every Unity script inherits from MonoBehaviour and has two core lifecycle methods:

using UnityEngine; public class PlayerController : MonoBehaviour { // Public variables appear in Inspector public float speed = 5f; private Rigidbody2D rb; // Start() runs once when the GameObject activates void Start() { // Cache components in Start, not Update rb = GetComponent<Rigidbody2D>(); } // Update() runs every frame void Update() { float h = Input.GetAxis("Horizontal"); rb.velocity = new Vector2(h * speed, rb.velocity.y); } }

Important Lifecycle Methods

  • Awake() — runs before Start, even if script is disabled. Use for initialization.
  • Start() — runs once on first frame. Use for setup that needs other objects ready.
  • Update() — runs every frame. Use for input and game logic.
  • FixedUpdate() — runs at fixed rate (50/sec). Use for Rigidbody physics.
  • LateUpdate() — runs after all Updates. Use for camera following.
  • OnCollisionEnter2D() — triggers when collider hits another collider.
  • OnTriggerEnter2D() — triggers when entering a trigger collider.
  • OnDestroy() — runs when the GameObject is destroyed.

Object Pooling — Essential for Mobile

Instantiating and destroying objects every frame causes garbage collection spikes on mobile. Use object pooling instead — create a pool of pre-made objects and reuse them:

// Instead of: Instantiate(bullet) and Destroy(bullet) // Use: Get from pool and return to pool void Shoot() { GameObject bullet = bulletPool.Get(); // get from pool bullet.transform.position = firePoint.position; bullet.SetActive(true); } void ReturnBullet(GameObject bullet) { bullet.SetActive(false); bulletPool.Release(bullet); // return to pool }

Unity Physics — 2D vs 3D

Rigidbody2D — 2D Physics

Add Rigidbody2D component for gravity and physics-based movement. Set Body Type to Dynamic for moving objects, Kinematic for player-controlled movement, Static for walls and platforms. Use rb.velocity for movement, rb.AddForce() for impulses.

Colliders

BoxCollider2D for rectangular objects, CircleCollider2D for round objects, PolygonCollider2D for custom shapes. Enable "Is Trigger" on a collider to detect overlap without physical collision. Always use simple collider shapes — they are cheaper than complex ones.


ScriptableObjects — Data Management

ScriptableObjects store game data separately from scene objects — great for items, enemies, and level configs:

[CreateAssetMenu(menuName = "Game/Enemy Data")] public class EnemyData : ScriptableObject { public string enemyName; public int health; public float speed; public int damage; public Sprite sprite; }

Create instances via right-click in Project window → Game → Enemy Data. Assign to enemy scripts via Inspector. Change stats without touching code.


Unity Best Practices for Mobile

  • Use IL2CPP scripting backend (faster than Mono on Android)
  • Target ARM64 architecture only (required by Google Play)
  • Enable Strip Engine Code — removes unused Unity modules from build
  • Use Addressables for large asset management instead of Resources folder
  • Profile with Unity Profiler before optimizing — don't guess bottlenecks
  • Disable Auto Sync Transforms in Physics settings if not needed
  • Use Sprite Atlases to batch 2D draw calls
  • Cache Camera.main — it does a Find() every call
Build Size Tip: Check your APK/AAB size in Build Settings after building. Target under 50MB for best install rates on mobile. Use texture compression (ETC2 for Android) and audio compression to reduce size.