Creating the Character GameObject

Now that we have the major components of the appearance of our character, we need to create it in the game world.

In the Hierarchy tab, on the left-hand side of the Editor window, right-click and select Create New.

This will add an empty GameObject to your scene.

Tip

If you still have the Animator window open, click on the Scene tab at the top of the Editor window.

  1. Make sure that the new empty GameObject is selected. Click on Add Component at the right-hand side of the Editor window in the Inspector tab.
  2. Search for Sprite Renderer and click on Sprite Renderer from the list.
  3. In the Assets/Character folder, select CharacterSheet and click and drag it onto the Sprite section of Sprite Renderer.
  4. You'll see that the sprite gets named as the first child element of the CharacterSheet object: CharacterSheet_0. This is correct and fine.
  5. Next, we need to add an Animator component to GameObject.
  6. In the Inspector window, click on Add Component.
  7. Search for Animator and then click on Animator to add it:
    Creating the Character GameObject
  8. In the Assets/Character folder, click on the CharacterSheet_0.controller file and drag it into the Controller section of Animator.
  9. Next, let's name GameObject to something we can relate to. I will use Character. You can name it anything you'd like, although organization is important in games, so try to choose something that is easy to recognize.
  10. You'll see that the character is facing the wrong direction.
  11. In the Inspector tab under Transform, change Scale on the X axis from 1 to -1. This will flip the character to face the correct way for the game.

Tip

If you play the game now, you'll see the character running.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset