Codédex | Create Your First Scene with Unity and C#

Create Your First Scene with Unity and C#

Julien Kris
·
60 min read
·
Jul 1, 2026

Prerequisites

Introduction

Unity is one of the world's most popular game engines, and developers use C# to bring their games to life. Popular indie games like Hollow Knight, Cuphead, and Among Us were all built with Unity and C#.

In this project tutorial, you'll build a small 3D world and write your first Unity script to create a simple dawn (sunrise) to dusk (sunset) cycle. By the end, you'll have a scene where the sun automatically moves across the sky, bringing your world to life. 🌅

Before you start: Make sure to install Unity Hub, a Unity Editor version set up, and a new Universal 3D project ready to go. If you haven't done that yet, follow Unity's setup guide first, then come back here.

What You'll Build

You'll build a simple 3D scene featuring:

Along the way, you'll learn how to:

Creating a World

Open your project in the Unity Editor.

You'll see a few panels. Here's what they do:

Let's start by creating some terrain.

From the top menu, choose GameObject → 3D Object → Plane.

This will become the ground for your world.

Add Some Color

In the Project Window, click the + and choose:

Create → Material

Name it Grass.

With the material selected, change the Base Map in the Inspector to any shade of green.

Drag the Grass material onto your Plane.

Now your world has some grass! 🌱

Add a Centerpiece

Every world needs something interesting for the sun to shine on.

Go to:

GameObject → 3D Object

Choose one of Unity's built-in shapes:

Place it on top of your Plane.

Feel free to move, rotate, and scale it using Unity's tools. You can also create a new material, and apply it to your shape.

This object will become the centerpiece of your world. As the sun moves throughout the day, you'll notice how the lighting and shadows change across its surface.

The scene already includes a Directional Light in the Hierarchy.

This is going to be your sun.

Watching the Sun Move

Before writing any code, let's see what we're trying to automate.

Select the Directional Light in the Hierarchy.

Then grab the Rotate Tool from the toolbar (or press E) and drag the red rotation ring.

Notice what happens:

Right now you're rotating the sun by hand.

Next, we'll write code that does this automatically.

Your First Unity Script

In the Project Window, click the + and choose:

Scripting → Create MonoBehaviour Script

Name it:

DayCycle

Open the script and replace everything with:

using UnityEngine;

public class DayCycle : MonoBehaviour
{
    public float rotationSpeed = 10f;

void Update()
    {
        transform.Rotate(rotationSpeed * Time.deltaTime, 0, 0);
    }
}

A few things to notice:

Select the Directional Light in the Hierarchy.

Then drag DayCycle.cs onto the Inspector to attach it.

Press Play.

Your sun now rotates automatically, creating a simple day and night cycle. ☀️

Customize Your World

Now it's your turn to experiment.

Change the Speed

Select the Directional Light.

In the Inspector, you'll see your Rotation Speed variable.

Try changing it:

Rotation Speed Effect
5 Slow, peaceful sunrise
10 Default
25 Fast-moving day
50 Time is flying!

How does each speed change the feeling of your world?

Try Different Colors

Create a few more Materials and experiment with different colors.

Try adjusting the sliders for Metallic Map and Smoothness.

How does the sunlight look as it moves across each material?

Build Something Bigger

Instead of using just one object, build a small scene.

Can you make:

Watch how the shadows change throughout the day.

Bonus Challenge: Announce the Time of Day

Right now, your sun moves silently across the sky.

Can you make your program announce each phase of the day as the sun moves?

Your Console should print messages like:

🌅 Sunrise
☀️ Morning
🏞️ Afternoon
🌇 Sunset
🌙 Night

Try to print each phase only once as the sun enters it. For example, once you've printed "Morning", it shouldn't print "Morning" again until the next cycle.

Hints

string[] timesOfDay =
{
    "Sunrise",
    "Morning",
    "Afternoon",
    "Sunset",
    "Night"
};

Conclusion

Congratulations! 🎉

You've just written your first Unity behavior. With only a few lines of C#, you've created a world where time passes automatically. The same idea can power spinning planets, moving platforms, weather systems, dynamic lighting, and countless other game mechanics.

Keep experimenting! Add more objects, create new materials, adjust the speed of the sun, and build a world that's uniquely yours.

Resources

Optional: Import Your Own Model

Want to personalize your world even more?

Try downloading a free 3D model from websites like Kenney or Poly Pizza.

When choosing a model, keep these tips in mind:

Once you've downloaded a model, drag it into your Project Window. Unity will import it automatically. Then drag it from the Project Window into your Scene to add it to your world.

Have fun experimenting and making your world your own!