Answer the question
In order to leave comments, you need to log in
How to make a car purchase?
Please help me how to make a car purchase through points? I didn’t take the script from the Internet, here the car opens if Level 1 passes for 3 stars, but I need, for example, 500 points and the car opens.
Script Point they are automatically saved.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Shop : MonoBehaviour {
public ScoreManager Pointt;
public int scoreValue;
public Image[] cars;
public Button[] bttns;
public Text[] carsText;
public string[] levels;
public GameObject Netudeneg;
void Start () {
Pointt = FindObjectOfType <ScoreManager> ();
cars [PlayerPrefs.GetInt ("c")].color = Color.white;
if (PlayerPrefs.GetInt(levels[0]) == 3)
{
bttns [0].interactable = true;
carsText [0].gameObject.SetActive (false);
}
/*if (ScoreManager.point >= 500)
{
ScoreManager.point -= 500;
}
else if (ScoreManager.point < 500)
{
Netudeneg.SetActive (true);
}*/
}
void Update ()
{
}
}
Answer the question
In order to leave comments, you need to log in
For starters, what nonsense. You can not take away at the start every time 500 points from the player.
the first time he started the game with 600 points and was left with a hundred and an open car. next time he will have zero points and no car.
If it is the points scored that need to be spent on opening the content (in this case, the car), then at least save (remember that he has already opened it), in the same PlayerPrefs
. with stars. (although you seem to need the first option)
And on Update() save to PlayerPrefs ?? Seriously? why write each frame if we know exactly when the number of points changes?
save in the AddPoints() method and in the subtract points method if it is separate)
if (ScoreManager.point >= 500) {
ScoreManager.point -= 500;
bttns [0].interactable = true;
carsText [0].gameObject.SetActive (false);
}
else {
Netudeneg.SetActive (true);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question