• 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

How to count the number of strings in a string class? 2 Answers

[c#] Save an instance for future re-instantiation 0 Answers

Most efficient way to convert string[] to int [] in C#? 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