We now add the main character in our game, which is the little alien named Space Buddy. To add the alien, we do the following:
Move it to the sprites folder.
Create a sprite GameObject using the following image:
Name the GameObject
SpaceBuddy
.Go to Add Component | Physics 2D | Rigidbody 2D.
Go to Add Component | Physics 2D | Box Collider 2D.
Go to Add Component | New Script and name the script
SpaceBuddy.js
.In the Project Browser, add a folder named
Scripts
and moveSpaceBuddy.js
into it.Add the following code to the script:
Note
The first line of code is used to ensure strict typing—if you use the same variable for different data types, then an error will be thrown when building the script.
This prevents bugs related to incorrect data types from occurring. Have a look at the next line of code.
#pragma strict