We are now going to create a script that will enable us to control our character.
Note
We do not build our scripts until we have added all of them as some of them may need to communicate with each other and we will get errors when they do not exist yet and are therefore unknown. Also, we do not actually need to build the scripts as Unity automatically does this. However, it is good practice as it helps to check for errors.
We will control a spaceship, moving it left and right. The following are the steps to do this:
Download the free public domain spaceship art from the following URL:
We will use the
Rocket.png
asset as our character sprite.Create a new sprite GameObject, name it
Ship
, and assign theRocket.png
file shown in the following image as the sprite:Create a folder by right-clicking in the Project Browser and going to Create | Folder. Name the folder
Code
.Create a new script in our
Code
folder and go to Create...