Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 staryzhelios · Apr 29, 2019 at 06:25 AM · textsavesizeslidersave data

my text size changes didnt saved by slider

Hello I want my changes of text's size be saved even after go next page and came back to same page.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class SliderText2 : MonoBehaviour
 {
 
 
     public Text text2;
     float textvalue =45;
     public Slider Slider;
 
     void Start()
     {
 
             text2 = GetComponent<Text>();
         //text2.fontSize = 45;
         PlayerPrefs.GetFloat ("Slider");
     }
 
     // Update is called once per frame
     public void textUpdate2(float slidervalue)
     {
         
         //text2.fontSize = slidervalue;
         textvalue = slidervalue;
         text2.fontSize = Mathf.RoundToInt(textvalue*100);
         PlayerPrefs.Save ();
 
     }
 
 
 
 
 
 }
 
Comment
Add comment
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

1 Reply

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

Answer by fafase · Apr 29, 2019 at 06:34 AM

You are not saving the new value. PlayerPrefs.Save is not meant to update the value.

  void Start()
  {
          text2 = GetComponent<Text>();
          // text2.fontSize =  PlayerPrefs.GetFloat ("Slider", 45);
         text2.fontSize =  PlayerPrefs.GetInt ("Slider", 45);
  }
 
  public void textUpdate2(float slidervalue)
  {
      text2.fontSize = Mathf.RoundToInt(textvalue*100);
      // PlayerPrefs.SetFloat("Slider", text2.fontSize);
     PlayerPrefs.SetInt("Slider", text2.fontSize);
  }


The start method tries to get the Slider value from prefs and if there is none then 45 is assigned. When you update the text, the value is also saved with the Slider key. Next time Slider key is accessed from prefs, it should return the value.

Comment
Add comment · Show 3 · 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 staryzhelios · Apr 29, 2019 at 07:10 AM 0
Share

Oh I see..Tqs alot!! Btw why it said....

Assets/SliderText2.cs(18,33): error CS0266: Cannot implicitly convert type float' to int'. An explicit conversion exists (are you missing a cast?)

avatar image fafase staryzhelios · Apr 29, 2019 at 10:20 AM 1
Share

I guess it is happening on the SetFloat, it should be SetInt since you are setting an integer.

avatar image staryzhelios fafase · Apr 29, 2019 at 01:03 PM 0
Share

I never know that Get also can can to GetInt! Tqs im so noob.. It's working now ! Tqsm !! :')))) <3

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

114 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving a UI Text Number Multiple Times 2 Answers

Set generated text size inside layout group 0 Answers

Is there a way to save a 2D characters path and replay it on respawn? 0 Answers

How can I change the text size on iOS and Android? 4 Answers

how to scale and position guiText in android 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