question

Saphal Aryal avatar image
Saphal Aryal asked

Instanciate the corresponding character according to selected and purchased character

Hi ! I have a shop system where player can purchase and equip character and my question is :

1> how could I equip the previously equipped character whenever player opens the game.

2> How could I instanciate corresponding character according to purchased and equipped character.

Player Inventory
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Rick Chen avatar image
Rick Chen answered

>>how could I equip the previously equipped character whenever player opens the game.

You can store the last equipped character’s id in the player data when the player saves the game. Next time they open the game, they can retrieve the last equipped character’s id with GetUserData API.

>> How could I instanciate corresponding character according to purchased and equipped character.

Once the player purchased the character, they can use the GrantCharacterToUser API to get the character instance.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Saphal Aryal avatar image Saphal Aryal commented ·

@Rick Chen Thanks for your reply :) !

How does the GrantCharacterToUser Works?

I have a character prefab named "Normal Character" .

1>How can I instanciate that prebab when I purchase the Normal character from inventory .

2>What should I pass in CharacterName ? ( Should I have to pass prefab name or else )

Could you provide me some code . I am confused about it .

0 Likes 0 ·
JayZuo avatar image JayZuo ♦ Saphal Aryal commented ·

>>How does the GrantCharacterToUser Works?

When a player purchase a Character in your catalog, it goes to the player’s inventory as an item. The GrantCharacterToUser API simply converts this item to a Character for the player, and allow it to have name, data, statistic and etc, so that you can call the Character APIs on this character.

For how to instantiate a prefab, that's out of PlayFab's scope. It seems you are using Unity, you can seek for help on Unity Forums.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.