How to Use Unity: Step-by-Step Tutorial for 2D, 3D, C# Scripting & Mobile Deployment

2026-06-05·Troubleshooting

Key Takeaways

  • Unity uses a component-based system: attach scripts, colliders, and renderers to GameObjects.
  • For 2D projects, switch the editor to 2D mode before importing assets to avoid scaling issues.
  • C# scripts control behavior; start with `Update()` for real-time input and `Start()` for initialization.
  • Mobile deployment requires adjusting input (touch vs. keyboard) and optimizing graphics (reducing draw calls).

Getting Started with Unity: The First 30 Minutes

I remember my first Unity project—I spent an hour trying to move a cube because I’d never touched C#. Let me save you that pain. Download Unity Hub, install version 2022.3 LTS (long-term support), and open a new project. Choose “3D Core” for 3D games or “2D” for 2D. For this tutorial, start with 2D—it’s simpler for learning the basics.

Setting Up Your Scene

Once the editor loads, you’ll see five main panels:

  • Scene (where you arrange objects)
  • Game (what the player sees)
  • Hierarchy (list of GameObjects)
  • Inspector (properties of selected object)
  • Project (your files)

Right-click in Hierarchy > 2D Object > Sprite > Square. This creates a white square. In the Inspector, set its Position to (0, 0, 0) and Scale to (2, 2, 1). Now it’s a 2-meter square (in Unity units).

Pro tip: Unity’s default unit equals 1 meter. For 2D pixel art, set your sprite’s Pixels Per Unit to match your art (e.g., 16 for 16x16 pixel sprites). I once forgot this and my character was 10 meters tall.

Writing Your First C# Script

In the Project panel, right-click > Create > C# Script. Name it `PlayerMovement`. Double-click to open in Visual Studio (or your code editor).

Replace the default code with:

```csharp

using UnityEngine;

public class PlayerMovement : MonoBehaviour

{

public float speed = 5f;

void Update()

{

float moveX = Input.GetAxis("Horizontal");

transform.Translate(Vector2.right * moveX * speed * Time.deltaTime);

}

}

```

Save and go back to Unity. Drag the script onto your square in the Hierarchy. Press Play—use arrow keys to move left/right.

What’s happening:

  • `Update()` runs every frame (60 times per second at 60 FPS).
  • `Time.deltaTime` makes movement frame-rate independent (without it, your square moves faster on a 144Hz monitor).
  • `Input.GetAxis` returns -1, 0, or 1 for keyboard, but also works with joysticks.

Adding 3D Objects and Physics

For 3D, create a new project (3D Core). Add a Cube (GameObject > 3D Object > Cube) and a Plane (same menu). Position the plane at (0, 0, 0) and the cube at (0, 5, 0). To make the cube fall, select it and click Add Component > Physics > Rigidbody. Press Play—gravity pulls it down.

Comparison: 2D vs 3D Physics

Feature2D Physics3D Physics
---------------------------------
ComponentRigidbody2DRigidbody
CollidersBoxCollider2D, CircleCollider2DBoxCollider, SphereCollider
GravityDefault 9.81 (but in 2D plane)Default 9.81 in Y axis
Use casePlatformers, top-down gamesFPS, racing, open-world

I personally find 2D physics easier for prototyping because you don’t worry about Z-axis issues.

Building for Mobile Devices

Mobile deployment is where beginners hit walls. Here’s the checklist:

1. Switch Platform

Go to File > Build Settings. Select Android or iOS, then click Switch Platform. Unity will recompile your assets (takes 2-5 minutes).

2. Adjust Input

Replace `Input.GetAxis` with touch input:

```csharp

if (Input.touchCount > 0)

{

Touch touch = Input.GetTouch(0);

Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position);

// Move toward touchPos

}

```

3. Optimize Performance

Mobile GPUs are weak. In Player Settings:

  • Set Resolution Scaling to 0.75 (renders at 75% resolution).
  • Enable Dynamic Batching (reduces draw calls by combining meshes).
  • Use Quality Settings to disable shadows and post-processing.

4. Test on Device

Connect your Android phone via USB (enable Developer Options and USB Debugging). In Build Settings, click Build And Run. Unity compiles an APK and installs it. For iOS, you need a Mac and Xcode.

Real numbers: A simple 2D game with 10 sprites and 2 scripts runs at 60 FPS on a 2019 iPhone. Adding 3D models with 10,000 polygons each drops it to 30 FPS on older Android phones.

Common Pitfalls (and How I Fixed Them)

  • “Script is missing” error: Usually means you renamed the script file without matching the class name. Keep them identical.

  • Object doesn’t move: Check if you attached the script to the correct GameObject. Also ensure you’re not accidentally pausing the editor.
  • Build fails for Android: You need the Android SDK. Unity Hub can install it for you under “Add Modules” when you install the editor.

FAQ

Q: Can I use Unity for non-game apps?

A: Yes. Unity is used for architectural visualizations, training simulations, and even film pre-visualization. The same principles apply—you just replace game mechanics with navigation and UI interactions.

Q: How long does it take to learn Unity basics?

A: Most beginners can build a simple 2D game (like Pong) in 2-3 days of focused work. Mastering C# and 3D physics takes 2-3 months. I spent 4 months before I felt comfortable with mobile deployment.

Q: Why is my game lagging on mobile?

A: Check draw calls (Window > Analysis > Frame Debugger). Aim for under 100. Common fixes: combine sprites via Sprite Atlas, reduce particle effects, and lower texture resolution to 512x512 or 1024x1024.