0
0
Unityframework~15 mins

Debug.Log for debugging in Unity - Mini Project: Build & Apply

Choose your learning style9 modes available
Debug.Log for debugging
📖 Scenario: You are creating a simple Unity script to track the player's score during a game. You want to see the score updates in the Unity Console to make sure your code works correctly.
🎯 Goal: Build a Unity C# script that uses Debug.Log to print the player's score updates to the Console for easy debugging.
📋 What You'll Learn
Create an integer variable called score and set it to 0
Create an integer variable called pointsToAdd and set it to 10
Add pointsToAdd to score
Use Debug.Log to print the message "Score updated: " followed by the current score
💡 Why This Matters
🌍 Real World
Game developers use Debug.Log to check values and program flow while building games in Unity.
💼 Career
Knowing how to debug with Debug.Log is a basic but essential skill for Unity developers to find and fix issues quickly.
Progress0 / 4 steps
1
Create the initial score variable
Create an integer variable called score and set it to 0 inside the Start() method.
Unity
Need a hint?

Use int score = 0; inside the Start() method.

2
Add points to add variable
Inside the Start() method, create an integer variable called pointsToAdd and set it to 10.
Unity
Need a hint?

Use int pointsToAdd = 10; inside the Start() method.

3
Add points to the score
Inside the Start() method, add pointsToAdd to score using the += operator.
Unity
Need a hint?

Use score += pointsToAdd; to add points.

4
Print the updated score with Debug.Log
Use Debug.Log inside the Start() method to print the message "Score updated: " followed by the current score.
Unity
Need a hint?

Use Debug.Log("Score updated: " + score); to print the message.