- Home /
How to make an upgrading game?
I just made Roll-a-Ball and Survival Shooter from unity tutorials. So i am still a newbie to Unity. I want to make an upgrading game, where your character does something, like collecting things or shooting enemies to earn points, and then later, uses that points to buy upgrades for himself and be faster, have more health... or something like that. I work in Unity 5.
$$anonymous$$y question is: How can i spend my points to upgrade a character?
Cut your problem in small chunks. You want your character to have points in his health, power, speed etc. So, you'll need to add those as variables in a script. Your points will earn upgrades. That means simply to add more points to those attributes. Then you'll need to save those attributes in a file somehow and read it back when loading the game at a different time. The easiest and probably least correct way is through playerprefs. Least correct way because that should be used for game options and the like as it is easily modifiable from outside the game. You could check about serialization with Unity for save games.
Answer by NeverHopeless · Jul 08, 2015 at 10:40 AM
Your characters must have attributes like speed, health etc. So for example once the user buy some product e.g., energy drink that increases health upto 3% then that variable that controls the health should represent a 3% more value than the original (if it was 100 it will be 103 now) and character sprite can be upgrade too. You can save these parameters using PlayerPrefs
class.
$$anonymous$$y question is: How can i spend my points to upgrade a character?
Better follow some basic scripting tutorials of C#. As NeverHopeless said you can use PlayerPrefs to save your points that you achieve in the game + save your player stats.
You have to make some variables that defines health, speed etc. like "int health" Then you have a variable that is called "int upgradePoints" then you have a button so you can give "int health" some upgrade points. When you click on it upgradePoints -= 1;
and health +=1;.
if(health == 0){basichealth = 100;}
if(health == 1){basichealth = 110;}
you have to save health as a playerpref class so that you won't lose your points when the game re-loads.
Also you have to be aware that if(upgradePoints == 0) that you ofcourse can't upgrade your character. How you do it is up to you, maybe disable the collider for that button? It is just a suggestion.
Your answer
Follow this Question
Related Questions
Failed to Load Mono? 0 Answers
does unity run in the back ground? 1 Answer
Restart the scene without changing the scoreboard 0 Answers
Disabling and Enabling a collision 1 Answer