Workshop 2: Critical Thinking in Game Development
Introduction to Unity Editor & C# Scripting
Game Development Skills
Core Competencies
- Learning - Continuous adaptation
- Critical Thinking - Design decisions
- Problem Solving - Debug & iterate
- Mathematics - Probability & functions
- Programming - Unity/C# mastery
- Creativity - Unique experiences
Unity Roadmap 🗺️
Where We’re Going in Unity
- Weeks 2-5: 2D Game Development
- Sprites, Physics2D, Tilemaps
- 2D Game Mini-Project
- Weeks 6-10: 3D Game Development
- 3D Models, Lighting, Physics
- Advanced Interactions
- 3D Game Mini-Project
- Final Project: Your Choice!
- Any Unity game or simulation
- 2D, 3D, or hybrid approach
Unity Editor Interface
Version Compatibility ⚠️
- Unity Editor interface varies by version
- Best Practice: Match tutorial version exactly
- If versions differ:
- Expect UI differences
- Research feature locations
- Check Unity documentation
You should have completed the Editor Interface tutorial
Layout Best Practices
Recommended “Tall” Layout Setup
- Window → Layouts → Tall
- Move Game View below Scene View
- Enable Console (Window → General → Console)
- Arrange for maximum workspace
Recommended “Tall” Layout
Benefits of Tall Layout
Scene View
- Maximum vertical space
- Better for level design
- Easier object placement
Game View + Console
- Test gameplay immediately
- See debug output live
- Catch errors quickly
Today’s Demo: Bearcat Wheel of Fate 🎯
What We’ll Build
- Interactive spinning wheel game
- Introduction to C# scripting
- Basic Unity 2D setup
- Input handling with new Input System
Project Setup
Creating a New 2D Project
- Unity Hub → New Project
- Select 2D (URP) template
- Name: “BearkatWheelOfFate”
- Choose location → Create
Import Assets
- Wheel sprite (provided)
- Marker/pointer sprite (provided)
- Drag into Assets folder
Scene Setup
Positioning GameObjects
- Wheel GameObject
- Position: (0, 0, 0)
- Scale as needed
- Marker GameObject
- Position above wheel
- Ensure proper sorting order
Introduction to C# Scripting
Creating Our First Script
- Assets → Create → C# Script
- Name:
WheelSpin
- Attach to Wheel GameObject
- Open in code editor
The WheelSpin Script
using System;
using UnityEngine;
using UnityEngine.InputSystem;
public class WheelSpin : MonoBehaviour
{
private float _rotationSpeed = 0.0f;
// Start is called once before the first execution of Update
void Start()
{
_rotationSpeed = 0.0f;
}
// Update is called once per frame
void Update()
{
// Check if the space bar was pressed this frame
if (Keyboard.current.spaceKey.wasPressedThisFrame)
{
_rotationSpeed = new System.Random().Next(2000, 5000);
}
if (_rotationSpeed > 0)
{
float rotationAmount = _rotationSpeed * Time.deltaTime;
transform.Rotate(0, 0, rotationAmount);
// Decrease rotation speed over time
_rotationSpeed -= 500 * Time.deltaTime;
}
}
}
Understanding the Script - Part 1
Key Components
- using statements - Import Unity functionality
- MonoBehaviour - Base class for Unity scripts
- **private float _rotationSpeed**
- Private: Only accessible within this class
- float: Decimal number type
- Underscore prefix: C# convention for private fields
Understanding the Script - Part 2
Unity Lifecycle Methods
void Start()
- Called ONCE when GameObject becomes active - Initialization code goes here - Runs before first Update()
void Update()
- Called EVERY frame (30-120+ times/second!) - Game logic and input checking - Performance critical code
Understanding the Script - Part 3
Transform & Rotation
- transform - Built-in reference to GameObject’s Transform
- Controls position, rotation, scale
- Rotate(x, y, z) - Rotates around each axis
- Z-axis rotation for 2D spinning
Time.deltaTime Explained
Frame-Independent Movement
- Time.deltaTime = Time since last frame
- Makes movement consistent across different framerates
- 60 FPS: deltaTime ≈ 0.0167 seconds
- 30 FPS: deltaTime ≈ 0.0333 seconds
Adding Debug Output
Debugging with Console
Testing Your Game
Play Mode Testing
- Save your script (Ctrl/Cmd + S)
- Return to Unity Editor
- Press Play button ▶️
- Press Spacebar to spin
- Watch Console for debug messages
Wheel Segments Decoded 🎰
Your Fate Awaits…
Bearcat Jackpot 🎉
You landed big! (good fortune)Mill Stream Mishap 🦆
Oops, you slipped by the ducks (bad luck)Star Trees Wish ⭐
Make a lucky wish under the trees
Wheel Segments (continued)
Waller Hall Haunt 👻
Unlucky… you met a campus ghostKaneko Lucky Break 🍕
You found free snacks in the loungeGoudy Gamble 🍽️
Mystery food choice, will it be lucky or not?
Input System Resources
Exploring Keyboard.current
Documentation
Key Takeaways
- Unity Editor layout affects productivity
- C# scripts bring GameObjects to life
- Start() initializes, Update() runs game logic
- Time.deltaTime ensures smooth movement
- Debug.Log() is your debugging friend
- Input System provides modern input handling
Next Lecture Preview
Gearing Up Towards the 2D Mini-Game Project 🎮
- Sprite animations
- Tilemap environments
- Player movement & collision
- Enemy AI basics
- Collectibles & UI
Questions & Practice Time
Your Turn!
- Modify the spin speed range
- Add different input keys
- Experiment with rotation direction
- Add sound effects (stretch goal)
Remember
- Save scripts before testing
- Check Console for errors
- Experiment and have fun!