Skip to content Skip to sidebar Skip to footer

Widget HTML #1

Third Person Shooter Survival Game in Unity 2024

Third Person Shooter Survival Game in Unity 2024

Hello everyone! My name is Al Ridley and I have been working as a freelance Unity developer for about a decade now.

Enroll Now

Creating a Third Person Shooter (TPS) Survival Game in Unity 2024 can be a rewarding and exciting project. Unity 2024, with its enhanced features and capabilities, offers a robust platform for game development. This guide will walk you through the essential steps to create a TPS survival game, from setting up the project to implementing key game mechanics.

Setting Up the Project

1. Installing Unity 2024: First, ensure you have Unity 2024 installed. Unity Hub is a great tool to manage different versions of Unity. Download Unity Hub, install Unity 2024, and create a new project. Select the "3D" template as the base for your game.

2. Project Structure: Organize your project folders. Create directories for Scripts, Prefabs, Materials, Textures, Audio, and Scenes. This organization will help keep your project manageable as it grows.

Creating the Player Character

1. Importing Assets: You can either create your own 3D models or use assets from the Unity Asset Store. For the player character, import a 3D model, animations (walk, run, shoot, idle), and necessary textures.

2. Setting Up the Player: Drag the player model into the scene. Add a Character Controller component to handle movement. Create a new script, PlayerController.cs, and attach it to the player. This script will handle player movement and shooting mechanics.

using UnityEngine; public class PlayerController : MonoBehaviour { public float moveSpeed = 5f; public float turnSpeed = 720f; public Camera playerCamera; public GameObject bulletPrefab; public Transform bulletSpawnPoint; public float bulletSpeed = 20f; private CharacterController controller; void Start() { controller = GetComponent<CharacterController>(); } void Update() { Move(); Shoot(); } void Move() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); Vector3 direction = new Vector3(horizontal, 0, vertical); if (direction.magnitude > 0.1f) { direction = Quaternion.Euler(0, playerCamera.transform.eulerAngles.y, 0) * direction; controller.Move(direction * moveSpeed * Time.deltaTime); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), turnSpeed * Time.deltaTime); } } void Shoot() { if (Input.GetButtonDown("Fire1")) { GameObject bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation); Rigidbody rb = bullet.GetComponent<Rigidbody>(); rb.velocity = bulletSpawnPoint.forward * bulletSpeed; } } }

Creating the Environment

1. Terrain: Use Unity's Terrain tools to create a basic landscape. Sculpt hills, valleys, and add textures to create a believable environment. You can also add trees, grass, and other vegetation.

2. Obstacles and Cover: Place various obstacles in the scene, like rocks, barrels, and buildings. These will provide cover and make the gameplay more dynamic.

Enemy AI

1. Enemy Model: Import or create a 3D model for the enemy. Ensure it has animations for idle, walk, and attack.

2. Setting Up the Enemy: Drag the enemy model into the scene. Add a NavMeshAgent component to handle pathfinding. Create a new script, EnemyAI.cs, to control enemy behavior.

using UnityEngine; using UnityEngine.AI; public class EnemyAI : MonoBehaviour { public Transform player; public float detectionRange = 10f; public float attackRange = 2f; public float moveSpeed = 3f; public float attackCooldown = 1.5f; private NavMeshAgent agent; private Animator animator; private float lastAttackTime; void Start() { agent = GetComponent<NavMeshAgent>(); animator = GetComponent<Animator>(); agent.speed = moveSpeed; } void Update() { float distanceToPlayer = Vector3.Distance(player.position, transform.position); if (distanceToPlayer <= detectionRange) { agent.SetDestination(player.position); if (distanceToPlayer <= attackRange) { if (Time.time - lastAttackTime >= attackCooldown) { Attack(); lastAttackTime = Time.time; } } } else { agent.ResetPath(); } animator.SetFloat("Speed", agent.velocity.magnitude); } void Attack() { animator.SetTrigger("Attack"); // Implement attack logic, e.g., reduce player health } }

Health and Damage System

1. Player Health: Create a Health.cs script and attach it to the player. This script will manage the player’s health and handle damage.

using UnityEngine; public class Health : MonoBehaviour { public float maxHealth = 100f; private float currentHealth; void Start() { currentHealth = maxHealth; } public void TakeDamage(float amount) { currentHealth -= amount; if (currentHealth <= 0) { Die(); } } void Die() { // Implement death logic, e.g., respawn or game over } }

2. Enemy Health: Similarly, attach the Health.cs script to the enemies, adjusting their health values accordingly. Ensure the player’s bullets deal damage to enemies.

User Interface

1. Health Bar: Create a UI Canvas and add a health bar for the player. Use Unity’s UI tools to create a simple health bar that updates based on the player’s current health.

2. Ammo Count: Add a text element to display the player’s current ammo count. Update this UI element in the PlayerController script whenever the player shoots.

Game Mechanics

1. Ammo and Reloading: Enhance the shooting mechanics by adding ammo management and reloading functionality.

public class PlayerController : MonoBehaviour { // Existing variables... public int maxAmmo = 30; private int currentAmmo; public float reloadTime = 2f; private bool isReloading = false; void Start() { // Existing initialization... currentAmmo = maxAmmo; } void Update() { if (isReloading) return; if (currentAmmo <= 0) { StartCoroutine(Reload()); return; } // Existing update logic... } void Shoot() { if (Input.GetButtonDown("Fire1") && currentAmmo > 0) { currentAmmo--; // Existing shooting logic... } } IEnumerator Reload() { isReloading = true; // Play reload animation yield return new WaitForSeconds(reloadTime); currentAmmo = maxAmmo; isReloading = false; } }

2. Enemy Waves: Implement an enemy wave system to increase difficulty over time. Create a WaveManager.cs script to spawn enemies in waves.

using UnityEngine; public class WaveManager : MonoBehaviour { public GameObject enemyPrefab; public Transform[] spawnPoints; public int enemiesPerWave = 5; public float waveInterval = 30f; private int waveNumber = 0; void Start() { StartCoroutine(SpawnWave()); } IEnumerator SpawnWave() { while (true) { waveNumber++; for (int i = 0; i < enemiesPerWave; i++) { Transform spawnPoint = spawnPoints[Random.Range(0, spawnPoints.Length)]; Instantiate(enemyPrefab, spawnPoint.position, spawnPoint.rotation); } yield return new WaitForSeconds(waveInterval); } } }

Polishing the Game

1. Visual Effects: Add particle effects for gunfire, explosions, and blood splatters to enhance the visual experience. Unity’s Particle System can be used to create these effects.

2. Audio: Import sound effects for gunshots, explosions, enemy growls, and background music. Use Unity’s Audio Source components to play these sounds at appropriate times.

3. Animations: Ensure smooth transitions between animations using Unity’s Animator Controller. Create blend trees for movement animations and set up triggers for shooting and reloading animations.

Testing and Optimization

1. Playtesting: Regularly playtest your game to identify and fix bugs. Gather feedback from other players to improve the gameplay experience.

2. Optimization: Optimize your game for performance. Use Unity’s Profiler to identify and address performance bottlenecks. Reduce draw calls, optimize assets, and use Level of Detail (LOD) for distant objects.


1. Building the Game: Once your game is complete, build it for your target platform(s). Unity supports multiple platforms, including Windows, Mac, Linux, and consoles.

2. Distribution: Distribute your game through platforms like Steam,, or the Unity Asset Store. Ensure you follow platform-specific guidelines for submission.

By following these steps, you can create an engaging Third Person Shooter Survival Game in Unity 2024. The process involves setting up the project, creating the player and enemies, implementing core mechanics, and polishing the game for a great player experience. Unity 2024’s advanced features and tools make it easier than ever to bring your game ideas to life. Happy game development!