how to upgrade value in runtime and store it in player preff

how to upgrade value in runtime and store it in player preff , so when user again open the game, value get updated ,
how to create a script which communicate with player preff and the updated game object inspector value
any one can suggest any way , i am trying to create upgrade weapon , through coin earn by player


here is a damage variable , you can see different with different guns but script is same , so i want to change this damage variable value , i tried with to create with static variable but it apply to all guns same value !
so if i am upgrading pistol so damage value of pistol will have to upgrade only , can anybody suggest ho to do that

4802201–459248–Gun_Controller.cs (47.5 KB)
4802201–459251–PlayerPrefManager.cs (1023 Bytes)

Hey there,

i highly suggest you to watch some tutorials,

your cs files are horrible, its hard to look through,

your “Update” function have 800lines of code and 100 “if” statements.

where is even the “swtichGun” function?
where do you define the “weapons” etc? O.O

weapon switch gun script is separate if you want i can share it here

well it makes not much sense since your code is totaly messed up my friend :S

you need to make a seperated class for Weapons, Entitys, Bullets/Arrows, 1st/3rd person Controller , Camera, animations, sound etc…

your code wont work since there are 100 if statesments in one Update Line,

if you have teamspeak and teamviewer i would love to help you out and set all up from scratch

1 Like

Not to pile on but I agree with the posters above. The code is a wee bit out of control.

First thing: GET SOURCE CONTROL! Use git, commit your entire project to git. There’s plenty of great tutorials geared precisely towards git and Unity.

Now that it is in git, you have essentially a “save point” if anything goes wrong.

Now start to refactor, one step at a time, to break the code into related areas of concern.

Each time you pull something apart (see tutorials for how to) and test it to make sure it works, then commit ALL the changes that got you there (add files, modify files, delete files), and think of that as your new savepoint.

In all cases you always have every time you ever make a full commit to back up in case something goes wrong.

And as you refactor, be sure to test, test, test!

3 Likes

Don’t use static variables for things you want to be different between instances of the class. As for what you’re trying to do, I’m having difficulty finding where you’re trying to do it in your script. It is not necessarily bad to have some large scripts, but they need to be organized.

1 Like

okay it will be great :slight_smile: you are awesome
i am waiting !