Free Unity Starter Setup
A step-by-step guide to creating your first Unity 3D project, setting up a scene, and adding player movement with C# scripts.
A step-by-step guide to creating your first Unity 3D project, setting up a scene, and adding player movement with C# scripts.
MyFirstUnityGame).You need three main GameObjects: a Camera, a Player, and Ground.
Ground.20, 1, 20.0, -1, 0.GroundMat, pick a green colour, and drag it onto the Ground cube.Player.0, 2, 0.In the Project panel, right-click → Create → C# Script. Name it PlayerController. Double-click to open it, then replace the contents with:
using UnityEngine; public class PlayerController : MonoBehaviour { [Header("Movement")] public float speed = 8f; public float jumpForce = 8f; public float gravity = 20f; [Header("Ground Check")] public Transform groundCheck; public float groundDistance = 0.3f; public LayerMask groundMask; private Rigidbody rb; private bool isGrounded; void Start() { rb = GetComponent<Rigidbody>(); } void Update() { // Ground check isGrounded = Physics.CheckSphere( groundCheck.position, groundDistance, groundMask); // Read input float moveX = Input.GetAxisRaw("Horizontal"); float moveZ = Input.GetAxisRaw("Vertical"); // Build movement direction relative to camera Vector3 move = Camera.main.transform.right * moveX + Camera.main.transform.forward * moveZ; move.y = 0f; move = move.normalized * speed; // Apply horizontal velocity rb.linearVelocity = new Vector3( move.x, rb.linearVelocity.y, move.z); // Jump if (Input.GetButtonDown("Jump") && isGrounded) { rb.linearVelocity = new Vector3( rb.linearVelocity.x, jumpForce, rb.linearVelocity.z); } } }
Add an empty child to the Player (Right-click Player → Create Empty, rename to GroundCheck) and position it at 0, -1, 0. Assign it to the groundCheck slot on the script.
Create another C# Script named GameManager. This tracks score and manages game state.
using UnityEngine; using TMPro; public class GameManager : MonoBehaviour { public static GameManager Instance; [Header("UI")] public TextMeshProUGUI scoreText; public TextMeshProUGUI gameOverText; private int score = 0; private bool isGameOver = false; void Awake() { // Singleton pattern if (Instance == null) Instance = this; else Destroy(gameObject); } public void AddScore(int points) { if (isGameOver) return; score += points; scoreText.text = "Score: " + score; } public void GameOver() { isGameOver = true; gameOverText.gameObject.SetActive(true); gameOverText.text = "Game Over!\nFinal Score: " + score; } public void RestartGame() { UnityEngine.SceneManagement.SceneManager .LoadScene(UnityEngine.SceneManagement.SceneManager .GetActiveScene().buildIndex); } }
PlayerController and add it.GameManager (right-click Hierarchy → Create Empty).GameManager component to it.Ctrl+Shift+P).Next steps: Add collectible coins, enemies, a health system, or scene transitions to build a full game!
Check out our Unity C# Cheat Sheet for a quick reference of all the most-used patterns.
๐ Unity Cheat Sheet โ