I have a UI slider which opens up when a user taps on a flag of Asia on a map. The slider has a min value of 0 and max of 500, value set at 500 and the direction is Left to Right. Beside the slider I have a UI Text which is assigned to the slider and shows 500 and will decrease if the slider is moved left and increase to 500 if moved right again. The problem I am having is I also have another script that has resources set up to show the player the value that they need. They will then go and move the slider to that value and Hit ok . Youll see clearer in the code below.
UI Slider Class
public class SliderUIMoneyTextUpdate : MonoBehaviour
{
//string sliderTextString = "500";
string sliderTextString;
public Text sliderMoneyText;
public static int sliderMoneyValue;
public int totalMoney;
void Start()
{
totalMoney = PlayerPrefs.GetInt ("money", totalMoney);
}
public void textUpdate(float textUpdateNumber)
{
sliderTextString = textUpdateNumber.ToString ();
sliderMoneyText.text = sliderTextString;
int.TryParse (sliderTextString, out sliderMoneyValue);
SaveMoney ();
}
public void SaveMoney()
{
totalMoney += sliderMoneyValue;
PlayerPrefs.SetInt ("money", totalMoney);
}
}
Resource Class:
public class MoreResourceUI : MonoBehaviour
{
public static int resourceMoney;
public int AsiaMoney;
//Assign the Needed Money to the Countries
public void asiamoney (Text asiaMoney)
{
resourceMoney = AsiaMoney;
AsiaMoney = 400;
asiaMoney.text = "Money: " + AsiaMoney; //Output required Money Amount
}
In my Asia_Resources script I have an if statement. I have tried the == and <=, < and > but all produce the same outcome as when you click on asia the slider value is set to 500 and therefore is always greater than money. I need it to be 0 even though it is displayed as 500 to the user and therefore being able to save the number they submit and tun it through the if statement again !
Any ideas how to do this ?
public class Asia_Resources : MonoBehaviour
{
public static int Money_Asia;
public static int Troops_Asia;
public static int Weapons_Asia;
public int money;
public int troops;
public int weapons;
public int totalMoney;
void Awake()
{
Money_Asia = 0;
Troops_Asia = 0;
Weapons_Asia = 0;
}
public void UpdateResources()
{
Money_Asia = PlayerPrefs.GetInt ("money");
MoreResourceUI UImoney = GetComponent ();
UImoney.AsiaMoney = money; //set at 400
if (Money_Asia >= money)
{
Debug.Log ("HAHAHAHA");
USA_Points.USAPoints += 1;
}
}
}
↧