4.1 Game Coding Foundation Presentation_26.07.2023
4.1 Game Coding Foundation Presentation_26.07.2023
Fundamental building {
block.
Its purpose is // variables
to encapsulates data and // functions / methods
behaviour. // event handlers
Same as standard
variable.
1. C# Basics
Operators Arithmetic operators (+, -, *, /),
Allow you to perform Comparison operators (==, !=, <, >),
various operations on
Logical operators (&&, ||, !),
variables and values.
Assignment operators (=, +=, -=), and more. O
Enable you to perform
calculations, make // lives is equal to 3
comparisons and control lives = 3
program flow.
// Compare is DrinksOrder Water
DrinksOrder == “Water”
// isAllowed is false
!isAllowed
// score is equal to itself plus 1
float score += 1;
1. C# Basics
Conditional statements If-else Switch
The most commonly used if(lives == 0){ switch (object){
conditional statements is if- // then end the game case “collectible”:
else and the switch gameEnd();
statement. score += 1;
} break;
The switch statement case “enemy”:
provides multiple cases and lives -= 1;
executes the block of code
associated with the matching break;
case. }
1. C# Basics
Loops for (int i = 1; i <= 5; i++)
Used to execute a block of {
code repeatedly.
// repeat this command until i becomes
The for loop repeats a block
greater than or = to 5
of code a specific number of
times for as long as the }
condition is met.
The while loop repeats a
block of code as long as a while (isAllowed)
specific condition remains {
true.
// Code do this command for as long as
it is true
}
1. C# Basics
Functions/Methods void CheckLives(){
Functions (also called
methods) in C# allow you to // check to see if all lives are gone
encapsulate reusable blocks
of code.
}
They accept input
parameters, perform specific
operations and return values
(if needed).
1. C# Basics
Event handlers private void OnCollisionEnter2D(Collision2D collision)
A method that allows you to {
define custom behaviour that // add in commands for when we hit a specific item
should execute when a }
particular event is triggered.
GameObjects make up
the objects in your game.
They will be the base for
characters, objects and
environments.
A GameObject serves as
a container that holds
components and defines
the properties, behaviours
and relationships of the
objects in your scene. Components
attached to this
GameObject
2. Unity-specific concepts
Components
Components are modular
pieces of functionality that
you attach to
GameObjects.
They provide specific
behaviours or features to
the GameObject they are
attached to.