Computer Science Grade 5 20 min

4. Scripting in Game Engines: C# in Unity and Blueprint in Unreal Engine

Learn how to use scripting languages like C# in Unity and Blueprint in Unreal Engine to control game objects and implement game logic.

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define a function with parameters and explain its purpose. Create a simple script in C# (Unity) that uses a variable to track a score. Construct a basic Blueprint graph (Unreal Engine) that responds to a player event. Explain the concept of an array for storing multiple pieces of data. Compare and contrast text-based scripting (C#) with visual scripting (Blueprint). Describe a simple 'game state', such as a door being locked or unlocked. Debug a simple script by checking variable values and logical flow. Have you ever wondered how a game knows to give you a SUPER jump instead of a regular jump when you hit a special bounce pad? 🤔 Let's learn the secret code behind it! Today, we're diving deeper into game scripting! We'll learn...
2

Key Concepts & Vocabulary

TermDefinitionExample Function with ParametersA function is a named block of code that does a specific job. A parameter is extra information you give to the function to change how it does its job.A `Jump(height)` function. The `height` is a parameter. Calling `Jump(10)` makes you jump higher than calling `Jump(5)`. ArrayAn array is like a container or a list that can hold multiple values of the same type. Each item in the array has a numbered position, called an index, starting from 0.An array called `inventory` could hold all the items a player has picked up: `["sword", "shield", "potion"]`. `inventory[0]` would be "sword". Game StateThe 'state' of an object is its current condition. We use variables and conditionals to check and change a...
3

Core Syntax & Patterns

Defining a Function with Parameters C#: `void FunctionName(type parameterName) { // code here }` Blueprint: Create a new Function, go to its Details panel, and add an 'Input' with a name and type. Use this when you have a reusable action (like dealing damage or changing color) that needs to be slightly different each time you call it. The parameter is the information that makes it different. Accessing Array Elements Use the array's name followed by the index number in square brackets: `arrayName[index]`. Remember that computers start counting from 0! To get the first item in an array, you use `arrayName[0]`. To get the third item, you use `arrayName[2]`.

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
A special mushroom in your game doubles a player's score. This happens every second, for exactly 4 seconds. If the player's score starts at 3, what will their score be after the 4 seconds are up?
A.12
B.11
C.48
D.24
Challenging
In C#, you want to give a player a "warning" status if they are NOT poisoned AND their health is less than 25. Given `bool isPoisoned;` and `int health;`, which `if` statement is correct?
A.if (isPoisoned == true && health < 25)
B.if (!isPoisoned || health < 25)
C.if (isPoisoned && health > 25)
D.if (!isPoisoned && health < 25)
Challenging
In Blueprint, you are scripting a traffic light. It should be Green, then after 5 seconds, Yellow, then after 2 seconds, Red. What is the correct logical flow of nodes connected by execution pins after an 'Event BeginPlay' node?
A.Set color to Green -> Delay 5s -> Set color to Yellow -> Delay 2s -> Set color to Red.
B.Set color to Green -> Set color to Yellow -> Set color to Red -> Delay 7s.
C.Set color to Green -> Delay 5s -> Set color to Red -> Delay 2s -> Set color to Yellow.
D.Set color to Red -> Delay 2s -> Set color to Yellow -> Delay 5s -> Set color to Green.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Advanced Topics

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.