Class Hours: 10:05 – 2:40
Mr. Bohmann | wbohmann@ewsd.org
Week 31
10:05 Today’s Notes & Attendance
- Take a look at your mail this morning. Look in spam – Anything from Vermont Highway Safety Alliance?
- Breakout Games are due on Friday. Help each other. Develop a nice game. We’ll look at invoke method today and instantiate again which could be a fun way to do power ups, bonus lives, animated aliens, etc…. You are a game developer, have fun with it.
- Game Idea Generator – kind of nifty JS project
- Gold Medal Skills Winners – Tuesday, May 6th meeting @ 6pm. EHS Cafeteria. bring your paperwork and check
10:10 Monday Mail

10:12 Reviewing Instantate and Introducing Invoke Methods
Last Friday we learned about instantate as a tool to create PreFab objects during the game. We can even clean up our code some. Seems redundant to write CreateAsteroid function 3 times to create 3 asteroids. Let’s add a Loop to repeat a block of code.
C# For Loop
When you know exactly how many times you want to loop through a block of code, use the for
loop instead of a while
loop:
for (int i = 0; i < 3; i++)
{
CreateAsteroid();
}
//what this means is we are going to initialize a variable [i], check if a condition //is true (if i is less than 3) and if the condition is true we are going to add one //to the variable and loop this block until the condition is not met anymore
Statement 1 is executed (one time) before the execution of the code block.
Statement 2 defines the condition for executing the code block.
Statement 3 is executed (every time) after the code block has been executed.
Level Up – Round 3 – It’s getting heavy now – (We did round 1 and 2 last Friday)
Controlling Object Lifespans with Invoke and Coroutines
Can you think of some objects in your game that should have a limited lifespan? Power up, bullets, enemies spawning.
The word “invoke” means to cause or request something to happen. Within the Unity engine, invoke is used to mean “run a function“. You can define your own functions that contain script logic that needs to be run at a later time or regular intervals. Unity will then invoke that function based on the timing information you provide.
Invoke("CreateAsteroid", 3.0F); //you need a string of the method name and then the delay
The Invoke() function will only call the target function one time. But how can you cause a function to be
called repeatedly on a regular schedule? Unity has a second function called InvokeRepeating() that does the job!
InvokeRepeating(string functionName, float secondsDelay, float rate)
//for example this will create an asteroid after 3 seconds and 1 every second after
InvokeRepeating("CreateAsteroid", 3.0F, 1.0F);
A coroutine is when you create something and then you may want some other task to be performed on that object later. Like asteroids being created and then later they get smaller and disappear, or blow up or….. whatever we want. We’ll tackle coroutines in another lesson.
Your Turn:
In your Lunar Lander game, create some Aliens to appear at the start of your game. Can you do more than one kind of alien. Try using Instantiate and Invoke. Write your own method and then call that method in the Start(). Ask questions – don’t close your game if you have errors.
Then,
Instantiate some new objects at specific locations using your new knowledge. Maybe you instantiate a star each time the rocket lands correctly. Can you make the stars line up?
If we finish early, add scoring to your breakout game (if you do not have it). What about Game Over text, add that if you are missing. Do you have a win condition? Are your blocks different point values? If you hit a special block can you invoke a new object to destroy that’s worth more points!
10:50 Morning Break (10 minutes)

11:00 Finish up One Button Game Proposals

Ben, Elle, Tobi, Braden, Peyton, Aidan
11:30 Pro Grids and ProBuilder
Let’s create a new project – called ProBuilder.

Build, edit, and texture custom geometry in Unity using ProBuilder for in-scene level design, prototyping, blocking and setting up game environments. Many game devs also use the ProBuilder tools for production games. You’ve seen it in Crab Game from a couple years back.
Let’s take a spin through the tool.
Tools Used:
- ProBuilder – Go to Package Manager and Search Unity Registry for ProBuilder
- Starter Assets – First Person Updates Controller
12:25 Lunch
12:55 Independent Reading

1:20 Afternoon Break (10 minutes)

1:30 -1:55 GMetrix Course

1:55 Independent Production & Guided Support
- Breakout Game – Due Friday
2:38 Dailies
