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 27, 2015 at 07:48 PM · c#uitextsaveslider

Saving a UI Text Number Multiple Times

I have a UI slider set up and connected to a UI Text so that the text is displaying a number which is reduced if the slider is slid to the left and increased if slid to the right. I have this script for that purpose:

 public class SliderUIMoneyTextUpdate : MonoBehaviour 
 {
     string sliderTextString = "500";
     public Text sliderMoneyText;
 
     public static int sliderMoneyValue;
 
     public void textUpdate(float textUpdateNumber)
     {
         sliderTextString = textUpdateNumber.ToString ();
         sliderMoneyText.text = sliderTextString;
 
         int.TryParse (sliderTextString, out sliderMoneyValue);
     }
 }

It is on a canvas and an ok button below the slider. Ok button when clicked sets the canvas as not active. I want to click the ok button and whatever value was set for the slider, i want to save it. The next time its loaded up and moved and the ok button is pressed i want to save that value and add the two saved values together! any ideas how ? Im pressuming its to do with set and get PlayerPrefs or something but dont know how to go about it !

Comment
Add comment · Show 1
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 Surprisejedi · Apr 28, 2015 at 03:30 AM 0
Share

I tried running this and it looks like there's no such thing in the doc as

public "Text" slider$$anonymous$$oneyText;

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by siaran · Apr 27, 2015 at 10:24 PM

could do something like

put this at the end of your textUpdate function:

 totalMoney += sliderMoneyValue;
 PlayerPrefs.SetInt("money", totalMoney);

and on the top of your script

 int totalMoney;

 void Start(){
  totalMoney = PlayerPrefs.GetInt("money", totalMoney);
 }



Comment
Add comment · Share
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
0

Answer by Surprisejedi · Apr 28, 2015 at 03:17 AM

Oh, first did you make everything public? If you did then make sure you have this

 Using UnityEngine.UI;
 Using UnityEngine.UI;
 Using System.Collections;
Comment
Add comment · Show 1 · Share
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 Kinger61 · Apr 28, 2015 at 08:04 AM 0
Share

Yea sorry I already had that included I just didn't include it in this lol ! Sorry !

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

Problems in the script for making a text disappear after few seconds 2 Answers

How to change UI button of a particular gameobject to another UI button 0 Answers

Trying to move slider based off percentage of screen 1 Answer

Missing or garbled text in UI.Text 0 Answers

UI Slider, Save Values and Change Them 0 Answers


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