Y
Y
Yura Berezovsky2017-06-27 20:02:59
C++ / C#
Yura Berezovsky, 2017-06-27 20:02:59

Why is the shift not getting data from another script?

The script should remove the cost of the skin from the player's account, but as a result, nothing happens.
The function that should withdraw money:

void Update ()
    {
        if (oppAcc == true) { 
             if (playerInfo.gold >= mfb && playerInfo.crystals >= cfb)
             {
            playerInfo.gold = playerInfo.gold - mfb;
            playerInfo.skin = buttonClickedOnObjectForBuy;
            playerInfo.crystals = playerInfo.crystals - cfb;

             }
             if (playerInfo.gold < mfb || playerInfo.crystals < cfb)
             {
            playerInfo.skin = 999;
             }
        }


    }

Player:
public class PlayerInfo : MonoBehaviour {
    public int skin;
    public int weapon;
    public int gold ;
    public int crystals ;
    public int swords;

  // Use this for initialization
  void Start () {
  
  }
  
  // Update is called once per frame
  void Update () {
        gold = 10000;
        crystals = 10000;
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
devalone, 2017-06-27
@Jurajkeee

When you write code like this, a kitten dies somewhere in the world, don't be a monster! you can just and what is oopAcc? What is mfb, cfb? Write properly. Why skin 999? What is 999? id? Why not enum? Okay, these are the little things. What does this purchase code do in update? Reading the documentation https://docs.unity3d.com/ScriptReference/MonoBehav... update is called every frame, you will buy a lot of things while the oppAcc variable is true. Also what does this code do in update?

void Update () {
        gold = 10000;
        crystals = 10000;
  }

Perhaps the problem is this. Or maybe somewhere else.

D
Dmitry Eremin, 2017-06-27
@EreminD

what
?
Where is buttonClickedOnObjectForBuy defined?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question