Now that we can take pictures, let's create an enemy to take pictures of! We will perform the following steps:
Chapter 9Art AssetsGhost Model
location, you'll find a series of files. Go ahead and drag and drop the folder into your project.Ghost_mesh
object. Now, select the object to bring up its properties in the Inspector tab. Under Scale Factor in the Model tab, change the value to .10
to scale the object to 1/10th of its starting size. Then, check Generate Colliders, making sure to hit Apply.Now, save the project, level and start up the game.
And now, the character is displayed and we can see them in the game. Spooky!
We oftentimes write code to provide the reactive or interactive parts within our simulation (or game world)—things such as when you're pressing a button or if you're walking or jumping. If you look at real life, you should note that a lot of things are reactive systems in that same way, such as your mobile phone and toaster. Depending on the stimuli provided to these objects, the state of these objects may change. We describe something that can be in one of the multiple states at a time as a state machine.
Almost every program that we write is or can be a state machine of some sort because technically, the moment you write an if
statement, you've created code that can be in one of at least two states. However, having a number of switch
and if
statements can quickly get out of hand, making it very hard for people to understand what your code is actually doing. As a programmer, we want to isolate problems and break them down into their simplest parts before jumping in to solve them.
There are different kinds of state machines, but for this first example, we are going to create a simple Finite State Machine (FSM). When I say finite, it means that each of the states is already defined ahead of time. With a finite state machine, we can have different states in which we can process input differently depending on the state.
For example, if you are on a ladder, you can only move up and down and not to the sides.