- Home /
In-Game Store Using Collected Coins
Hey everybody! So I have an FPS shooter prefab with 3 weapons. On each level the shooter collects coins that add to his score (in the ScoreSystem script). What I wanted to do was for the coin value (ScoreSystem) to save and then when I go to the "Shop", which is a separate level, I would have the ability to buy weapons that get permanently added to the player prefab while the application is open. What scripts would I need where and what should I change to what I already have? The following link contains my scripts and the setup of the player prefab, let me know if you need more information: http://unityimageprobs.wordpress.com/2012/08/09/fps-ingame-store/
So here's what I don't know:
-access the score in the store -how to make a store where I can spend points/coins to buy new weapons to add to my prefab player
-how to actually set up the store
-how to get the weapons to be added and stay
-How to get the bought weapons to go to the object of the playerr
Thanks!!
EDIT!!!! THIS IS WHAT I HAVE SO FAR BASED ON SMALL CLIPPITS OF ANSWERS! THANKS! You have to read it to understand though: http://unityimageprobs.wordpress.com/2012/08/11/my-current-unworking-setup-for-the-store/
Answer by ScroodgeM · Aug 11, 2012 at 12:00 AM
hmm. you should detach an object that you want to save between scenes from object that you want to change. detach it and use another way to set references or detach and attach again on scene loading to new player.
Wait, Now on most levels the Score Stays, but when I use a GUI button to go to another level, the score resets! Im so confused! This is the Setup of the Store based on all of your answers so far... You have to read it to understand though: http://unityimageprobs.wordpress.com/2012/08/11/my-current-unworking-setup-for-the-store/
check that you have only one score script. check that you don't set scores externally like on initialization. if no success, make a getter/setter for score values and insert Debug.Log() to setter. note when and who changes scores value.
Answer by IndieScapeGames · Aug 09, 2012 at 09:37 PM
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
int coins;
void Awake() {
DontDestroyOnLoad(coins);
}
}
Use the DontDestroyOnLoad() method.
What would that be attached to? Would it work with my ScoreSystem because its Javascript...
this is an example, it needn't be attached, use
http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
in script needs to stay alive. this would work with JS too.
You could keep a GameObject with a script containing "DontDestroyOnLoad(this)". This object will keep the player's data and will be present in all the scenes. If you want to get or add some data, you can simply ask to the script.
The prefab will then be loaded in the gameplay scene based on what this script says.
You didn't say if you are going to use a database. If the the game is offline it's a different approach for the store system.
Are you going to use a database?
Um, no I am not going to use a database. $$anonymous$$y game is offline. (Using Free Unity)
Answer by nixtwiz · Aug 11, 2012 at 09:16 PM
Why not use an I/O save system of some sort? Just have it save the amount of coins you collect at the end of each level to a file. Then the store accesses this file, reads the amount of coins you have and takes away how much you spend and then saves it again. Then it opens another file of what you have purchased, which is opened at the start of each level to see what weapons are available to you. The only problem with this is you would probably want to create a different language for it in a sense so players can't open the file and edit it. By this I mean making all numbers letters, making the numbers inverted, things like that that players may not be able to figure out. just something like "if this digit equals this, the digit in the in the int read and used in the code is equal to something else" <-my awesome psuedo code
Uh... That seems a little complicated, also seeing as I have already begun a current store. Thanks for the advice though! This is the Setup of the Store based on all of the answers so far... You have to read it to understand though: http://unityimageprobs.wordpress.com/2012/08/11/my-current-unworking-setup-for-the-store/
Your answer
Follow this Question
Related Questions
FPS Character with model 6 Answers
Respawn Player / enable new camera 0 Answers
FPS Arm Model 1 Answer
How do you change gravity with a press of a button? Unity 2D 2 Answers
Question about FPS Player Script 1 Answer