Characters


The Character functionality allows your players to select from multiple ‘characters’ where a character can represent an actual character or something like a vehicle or item that they will use.

Character functionality is based upon GameItem and it’s related classes and so also inherits all features such as the ability to use in app purchase, unlocking, selection screens, saving of information and so forth. It is worth reviewing the Game Structure overview page first as this page will focus on additions and differences from those documented there.

Setup

You can setup characters automatically through GameManager or manually through scripting. When using GameManager, you specify the number of characters that you want and then the Characters will be initialised based upon localisation strings and resource files as documented in the information about GameItems.

characterssetup

Automatic Character setup option in GameManager

You can then access all Characters through the GameItemManager available through GameManager.Instance.Characters.

Object Model

The Character class represents an instance of a Character and inherits from GameItem exposing all of the same properties and methods. Character overrides IdentifierBase to ‘Character’ and IdentifierBasePrefs to ‘C’ to distinguish it from other GameItems.

Configuration files should be placed into the Resources\Character\ folder with the name Character_<ID> where ID corresponds to the Character’s ID.

Character Selection

iPhone 3.5 @2x 960x640

A Character Selection Dialog

CreateCharacterButtons and CharacterButton behave in a similar to their base components for laying out the character selection display. CharacterButton additionally listens for messages of type CharacterPurchasedMessage to update the display automatically if they are purchased through in app purchasing.

The selected Character is always available through the GameManager.Instance.Characters.Selected property.

Character Display

The selected Character is always available through the GameManager.Instance.Characters.Selected property and so through this you can access things such as the currently selected Characters name, description, extension data etc.

The ShowCharacterInfo component can be added to a gameobject with a UI Text component to automatically update the Text display with customisable information about the currently selected Character.

Prefabs

Prefabs associated with Characters can be setup and retrieved as discussed in the description on GameItem.

The Character specific InstantiateCharacterPrefab component is an implementation of InstantiatePrefab that will use prefabs from the currently selected Character.

Sprites

Prefabs associated with Characters can be setup and retrieved as discussed in the description on GameItem.

The Character specific SetImageToCharacterSprite and SetSpriteRendererToCharacterSprite components behave in a similar to their base components for setting sprites from the currently selected character.

Unlocking

Like all GameItems you can have Characters in a locked status. Unlocking can be done through code, by collecting coins and adding a UI button with the UnlockCharacterButton attached or through in app purchase.

See also

If you have any thoughts or suggestions on improvements or additions to the Character features then please let us know!