Skip to content
ReadySpawn

How to make a first-person survival game in Unity

By Imersa Studios · Updated

A survival game is a loop: stats drain over time, the player gathers items to refill them, and progress is saved. Build that loop with three scripts (stats, pickup, save) before you add crafting or enemies.

1. Start with the loop

  • Stats drain: hunger and thirst go down every second.
  • The player looks for items and picks them up.
  • Using an item refills a stat.
  • Progress is saved so the next session continues.

Get this loop playable in a grey box level first. Crafting, building and enemies all sit on top of it.

2. Hunger and thirst in C#

using UnityEngine;

public class SurvivalStats : MonoBehaviour
{
    public float hunger = 100f, thirst = 100f;
    public float hungerPerSecond = 0.5f, thirstPerSecond = 0.8f;

    void Update()
    {
        hunger = Mathf.Max(0f, hunger - hungerPerSecond * Time.deltaTime);
        thirst = Mathf.Max(0f, thirst - thirstPerSecond * Time.deltaTime);
        if (hunger == 0f || thirst == 0f) Debug.Log("Starving");
    }

    public void Eat(float amount) => hunger = Mathf.Min(100f, hunger + amount);
    public void Drink(float amount) => thirst = Mathf.Min(100f, thirst + amount);
}

3. Pick items up

Cast a ray from the camera, and when it hits an item within reach, show a prompt and add the item on E. The inventory system guide walks through the raycast, the hotbar and dropping items with physics.

4. Save progress

Save the stats, the inventory and the player position into one class and write it as JSON. The save system guide has the full code, including safe file writes.

5. Block out the world

Survival needs a place worth exploring and items worth picking up. These packs and systems cover the first playable version:

The zombie and survival collection lists them in the order to get them, and the asset budget planner shows what fits your budget.

Play one before you build one

Survive It, from Imersa Studios (the team behind ReadySpawn), is a free 2D open-world survival game where everything you find can be picked up and crafted into tools. It is a quick way to feel how a crafting loop paces itself. See Survive It on the studio site.

Questions

Who wrote this

Imersa Studios builds the Unity systems, low poly packs and field guides sold on itch.io. The code and techniques here come from shipping those products. More about the studio.