Overview
Unity 2D Shooter Game is a fast-paced 2D arcade shooter built using Unity and C# scripting. The project focuses on core shooting mechanics, enemy AI, dynamic spawning, and an engaging game loop using Unity's 2D physics engine.
"Building a 2D shooter showcases fundamental game design principles, from player movement and weapon systems to enemy behaviors and scoring."
Key Features
Technical Implementation
The game leverages Unity's 2D object manipulation and physics to create a smooth gameplay experience. Object pooling is utilized to manage projectiles and enemies efficiently without triggering garbage collection spikes.
Player Controller (C#)
A snippet of how the player movement and shooting are handled:
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f;
public GameObject projectilePrefab;
public Transform firePoint;
public float fireRate = 0.2f;
private float nextFireTime;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent();
}
void Update()
{
HandleMovement();
HandleShooting();
}
void HandleMovement()
{
float moveX = Input.GetAxisRaw("Horizontal");
float moveY = Input.GetAxisRaw("Vertical");
rb.velocity = new Vector2(moveX, moveY).normalized * moveSpeed;
}
void HandleShooting()
{
if (Input.GetButton("Fire1") && Time.time >= nextFireTime)
{
Instantiate(projectilePrefab, firePoint.position, firePoint.rotation);
nextFireTime = Time.time + fireRate;
}
}
}
Installation & Usage
Running the game locally requires Unity Hub and Unity Editor.
- Clone the repository from GitHub:
git clone https://github.com/mskreallabs/Unity-2D-Shooter-Game.git. - Open Unity Hub, click Add, and select the cloned project directory.
- Ensure the correct Unity version is selected and launch the project.
- In the project browser, navigate to
Assets/Scenes/MainScene.unityand open it. - Press the Play button in the editor toolbar to run and test the game.