Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kinger61 · Apr 28, 2015 at 10:43 AM · c#javascriptuiplayerprefsslider

UI Slider, Save Values and Change Them

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<MoreResourceUI> ();
         UImoney.AsiaMoney = money; //set at 400
 
 
         if (Money_Asia >= money) 
         {
             Debug.Log ("HAHAHAHA");
             USA_Points.USAPoints += 1;
         }
     
     }
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image haim96 · Apr 28, 2015 at 11:18 AM 0
Share

sorry.. i read your question several times and couldn't understand your issue. can you explain shortly or add an image or something? any way, if this related, slider value is a float. you should mark use whole number. or use float for you money.

avatar image Ben-Stoneman ♦♦ · Apr 28, 2015 at 11:31 AM 0
Share

Just so we can understand better. The purpose of these scripts is to store and display the values of the sliders for asia?

avatar image Kinger61 · Apr 28, 2015 at 11:33 AM 0
Share

yea sorry guys bit confusing..yea i want to store and display values of asia which I am doing...the problem is as soon as the panel loads with the slider it carrys out that if statemtn ($$anonymous$$oney_Asia > money) due to the slider starting with the value 500 and the money having value of 400. I need that 500 value to basically not come into effect until i move the sliders and press the ok button, then do that if statement !

avatar image Ben-Stoneman ♦♦ · Apr 28, 2015 at 11:42 AM 0
Share

UpdateResources() is not invoked in your scripts.

It is very hard to help fix the logic in the script when the logic is so hard to follow.

The if statement is asking "is the Asia money value more than or equal to money" if it is add 1 to USA's points.

I find it very hard to understand what it is trying to do. Do you have any screenshots with some explaination on the purpose of the game/app?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Slider won't slide, issue assigning PlayerPrefs and then changing the PlayerPrefs' value 1 Answer

Updating UISlider with value from variable. 1 Answer

Wierd behaviour of slider when value is changed too fast 1 Answer

How to make if limit is reached then make sliders only slide back in ui (not forward) 2 Answers

Trying to move slider based off percentage of screen 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges