using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class BuyMovement : MonoBehaviour {
public Button MovBuyButton; // assign in the editor
public PlayerMovement spdmod;
public MoneyRegulator cash;
public Button ProgressBar;
public int level = 0;
public Sprite lev0, lev1, lev2, lev3;
void Start() {
MovBuyButton.GetComponent<Button>().onClick.AddListener(() => { buttonClicked(); });
}
void buttonClicked() {
if (level == 0 && cash.Cash > 500) {
cash.Cash -= 500;
spdmod.external_speed = 2;
level++;
Debug.Log ("Actually done.");
// gameObject.GetComponent<Image>().sprite = lev1;
ProgressBar.image.overrideSprite = lev0;
}
}
}
I have such code, when I press the button, 500 cash is gone, I get more speed, I level up, inspector says “Actually done”, no errors, but it still doesn’t change source of image. Could you please explain why?