How to Create a Simple Unity Game with C#: Jumping Ball, Score and Sound (Beginner Tutorial)
How to Create a Simple Unity Game with C#: Jumping Ball, Score and Sound (Beginner Tutorial)
In this tutorial, you will build a simple endless runner-style Unity game using C#. The player controls a ball that jumps over obstacles, gains score over time, and plays sound effects.
This project is designed for beginners and introduces essential Unity concepts step by step.
Game Features
- Automatic forward movement
- Jump with the Space key
- Obstacles moving toward the player
- Score system
- Sound effects
What You Need
- Unity Hub
- Unity LTS version
- Basic C# knowledge
Step 1: Create the Unity Project
- Open Unity Hub
- Create a new 3D Core project
- Name it JumpingBallGame
Step 2: Create the Player
Create a sphere:
- Hierarchy → Right-click → 3D Object → Sphere
- Rename it to Player
- Add a Rigidbody component
Step 3: Create the Ground
- Hierarchy → 3D Object → Cube
- Rename to Ground
- Scale it (X: 20, Y: 1, Z: 5)
- Set its Tag to Ground
Step 4: Player Movement and Jump Script
Create a C# script called PlayerController and attach it to the Player.
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float forwardSpeed = 5f;
public float jumpForce = 7f;
public AudioSource jumpSound;
private Rigidbody rb;
private bool isGrounded = true;
void Start()
{
rb = GetComponent();
}
void Update()
{
transform.Translate(Vector3.forward * forwardSpeed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
jumpSound.Play();
isGrounded = false;
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
isGrounded = true;
}
}
}
Add an AudioSource to the Player and assign a jump sound.
Step 5: Create an Obstacle
- Create a Cube
- Rename it to Obstacle
- Add a Box Collider
- Place it in front of the player
Obstacle Movement Script
Create a script called ObstacleMove and attach it to the obstacle.
using UnityEngine;
public class ObstacleMove : MonoBehaviour
{
public float speed = 5f;
void Update()
{
transform.Translate(Vector3.back * speed * Time.deltaTime);
if (transform.position.z < -10)
{
Destroy(gameObject);
}
}
}
Step 6: Score System
Create a UI Text element:
- Hierarchy → UI → Text (TextMeshPro recommended)
- Rename it to ScoreText
Create a script called ScoreManager:
using UnityEngine;
using TMPro;
public class ScoreManager : MonoBehaviour
{
public TextMeshProUGUI scoreText;
private float score;
void Update()
{
score += Time.deltaTime;
scoreText.text = "Score: " + Mathf.FloorToInt(score);
}
}
Attach this script to an empty GameObject called GameManager.
Step 7: Collision Sound and Game Over
Update the obstacle to detect collisions.
using UnityEngine;
public class ObstacleCollision : MonoBehaviour
{
public AudioSource hitSound;
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Player"))
{
hitSound.Play();
Time.timeScale = 0;
}
}
}
Add an AudioSource to the obstacle and assign a hit sound.
Step 8: Testing the Game
- Press Play
- The ball moves forward automatically
- Press Space to jump
- Score increases over time
- Collision stops the game
What You Learned
- Automatic movement
- Player input handling
- Basic physics
- UI and score system
- Audio integration
How to Improve This Game
- Spawn obstacles randomly
- Add background music
- Create a restart button
- Increase difficulty over time
Conclusion
This project shows how easy it is to create a complete mini-game using Unity and C#. With just a few scripts, you now have movement, score, and sound.
Unity and C# remain one of the best combinations for beginner game developers in 2026.

Comments
Post a Comment