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 eTavish · Nov 22, 2016 at 10:11 AM · c#stringvaluestucklocalscale

Add a value to a string

Hi, I've created a code that gets the localscale value and transforms it into a string then changes its unit of measurement to centimeters by multiplying it to 10. Problem is, it doesnt seem to work, are there any ways to add/subtract/multiply the localscale value that I've converted into string? Here's my vanilla code without formulas.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class ScaleSlider : MonoBehaviour {
 
     public Slider sliderLength;
     public Slider sliderWidth;
     public Slider sliderHeight;
     public Text textLength;
     public Text textWidth;
     public Text textHeight;
 
     // Use this for initialization
     void Start () {
         sliderWidth.value = 1f;
         sliderLength.value = 1f;
         sliderHeight.value = 1f;
     }
 
     void Update () {
         textLength.text = transform.localScale.x.ToString();
         textWidth.text = transform.localScale.y.ToString();
         textHeight.text = transform.localScale.z.ToString();
         transform.localScale = new Vector3(sliderLength.value*1, sliderWidth.value*1, sliderHeight.value*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 tanoshimi · Nov 22, 2016 at 10:11 AM 0
Share

Where are you multiplying by 10 exactly?

avatar image eTavish tanoshimi · Nov 22, 2016 at 10:15 AM 0
Share

At line 22-24. I removed the code since it didnt work out and was wondering if there's any other way.

avatar image Bunny83 eTavish · Nov 22, 2016 at 11:48 AM 1
Share

Wait, so you asked a question about some of your code doesn't work, but you removed that code from the question? So how should we tell what you did wrong?

avatar image Desoxi · Nov 22, 2016 at 10:36 AM 0
Share

If i understood you correctly you want to multiply the localscale values with 10.

  1. You are multiplying with 1 and not 10.

  2. You are not multiplying the localscale value, but a sliderLength.value, which initially is set to 1 and additionally is a string.

Why dont you use a float type for those variables (textLength etc.) and when you need them as a string you just could use ToString() as you already did with the localScale?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Nov 22, 2016 at 11:51 AM

Since you didn't include your problematic code in your question we can only guess. I think you want something like this:

 void Update ()
 {
     transform.localScale = new Vector3(sliderLength.value*1, sliderWidth.value*1, sliderHeight.value*1);
     
     Vector3 scale = transform.localScale * 10;
     textLength.text = scale.x.ToString();
     textWidth.text = scale.y.ToString();
     textHeight.text = scale.z.ToString();
 }
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

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Does unity C# support an exec method? 1 Answer

How to Instantiate from correct Icon. 1 Answer

Converting a string to an int 2 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