S
S
Sergey Klykov2016-06-08 19:03:19
Unity
Sergey Klykov, 2016-06-08 19:03:19

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.
a4c331e6ade249a69d6f5956a78b9945.pngec797203e1724e3eaea06e22bff22a22.png

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

2 answer(s)
D
Denis Gaydak, 2016-06-08
@DEMIGODDD

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)

X
xmoonlight, 2016-06-08
@xmoonlight

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 question

Ask a Question

731 491 924 answers to any question