Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Danieljarto · Aug 29, 2017 at 03:38 AM · unity 5guiprogramming

Charater selection with coins.

Hi! I have a plataform game mostly done, and i want to add coins in to the game and a charater selection so you can change your character expending some of your collected coins. How can i do this? I have searched for tutorials but i didnt found nothing. Please help!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LukeWaffel · Aug 29, 2017 at 07:29 AM

Hi!

I'm not sure wether or not you're looking for actual code examples or just a general way of thinking on how to implement the requested features, but for this post, I'll assume the latter.

First of all, you'd need to create some kind of coin prefab in your game. It should have a model (Or Sprite if your game is in 2D), appropriate colliders and a script. The script should check for trigger collisions with the player (A simple OnTriggerEnter with a tag or GameObject comparison should do the trick). Upon collision with the player, increase the amount of coins the player has collected during his current run. The amount of collected coins can be store in any script (Presumably the player script or a seperate score script).

When the player dies, save the amount of collected coins to either a file or the PlayerPrefs system (The latter is the easiest). You can use PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") + collectedCoinsVariable); All this does is increase the current saved Coins value by the amount of collected coins. Make sure to call PlayerPrefs.Save() after setting the int, otherwise the values won't get saved.

In your main menu, you can now display the total amount of coins by displaying the value of PlayerPrefs.GetInt("Coins").

For the character selection, you'll need to create a new script to hold information about each character. You'd start by creating a new script and making sure it doesn't inherit MonoBehaviour (You can easily do this by removing the : MonoBehaviour at the top of the script). You can now create variables for the name, description, price, model and what ever you want. Make sure to add a variable for keeping track wether or not the player owns the current character

Create a second script, which will act as the character store. That script will have a List of the just created character information script. You can now add as many characters as you want to the list. To purchase a character, create a function to check if the user has enough money, remove the required amount of coins if he has, and set the variable for keeping track of wether or not the user owns the character to true. For every character that the player owns, you can change the buy button to a select button. You can create a variable of the custom character info type to store the current selected character.

Now, in game, you can simply switch out the player model with the player model of the currently selected character.

I hope this somewhat helped!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

181 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How to make a Interactive Computer Screen in Unity 5.5? 1 Answer

Access function in another script cause Object reference error 1 Answer

Unlocking & "Equipping" Colors onto Sprites with c# 2 Answers

How can I make my navmesh agent stop in between travel to destination points? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges