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 princeadj14 · Dec 03, 2013 at 07:52 PM · converting

how to convert int to string in C#?

//1st script

string score="";

TimerScript.Seconds = score;

     score = GUILayout.TextField(score);
     GUILayout.EndHorizontal();
  
     if(GUILayout.Button("Save Your Time Record!"))
     {
         HighScoreManager._instance.SaveHighScore(name,System.Int32.Parse(score));
         highscore = HighScoreManager._instance.GetHighScore();
         Application.LoadLevel("Main_Menu");
     }

//2nd script

public float Seconds = 0;

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 princeadj14 · Dec 03, 2013 at 07:34 PM 0
Share

i have an error like this error CS0029: Cannot implicitly convert type string' to float' Corretion question ( How to convert string to float) please help me about this thankyou in advance! :/

avatar image KuPAfoo · Dec 03, 2013 at 07:55 PM 0
Share

You can search your error code to get a little tutorial on how to solve the error

I believe its a simple command like highscore = convertToString(score)

avatar image princeadj14 · Dec 03, 2013 at 08:24 PM 0
Share

by the way thanyou sir :)

avatar image zombience · Dec 03, 2013 at 09:28 PM 0
Share

don't forget to mark the question as answered if it has been solved.

2 Replies

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

Answer by zombience · Dec 03, 2013 at 07:54 PM

 float myNumber = 0.8f;
 
 void Start()
 {
     Debug.Log(myNumber.ToString());
 }



works for me

Comment
Add comment · Show 6 · 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 princeadj14 · Dec 03, 2013 at 08:12 PM 0
Share

sir i have an error here score = TimerScript.Seconds; //error CS0122: `Timer.Seconds' is inaccessible due to its protection level :(

     score = GUILayout.TextField(score);
     GUILayout.EndHorizontal();
  
     if(GUILayout.Button("Save Your Time Record!"))
     {
         HighScore$$anonymous$$anager._instance.SaveHighScore(name,System.Int32.Parse(score));
         highscore = HighScore$$anonymous$$anager._instance.GetHighScore();
         Application.LoadLevel("$$anonymous$$ain_$$anonymous$$enu");
     }
avatar image zombience · Dec 03, 2013 at 08:15 PM 0
Share

if you have access to the TimerScript, either change the Seconds variable from private/protected to public, or add the keyword "public" in front of it, like so:

 public class TimerScript
 {
     public float Seconds = .5f;  // should now be accessible
 }
 
avatar image KuPAfoo · Dec 03, 2013 at 09:08 PM 0
Share

That converts only in debug?

avatar image zombience · Dec 03, 2013 at 09:27 PM 1
Share

it converts anywhere you call the function.

 public class StringTest : $$anonymous$$onobehaviour
 {
 
     public string checkInspectorValue;
     private float convert$$anonymous$$e = 0f;
 
     void Update()
     {
         convert$$anonymous$$e += .01f;
         checkInspectorValue = convert$$anonymous$$e.ToString(); 
     }
 }

if you put that script on a gameobject, check the "checkInspectorValue" output in the inspector. you'll see the float value, but it will be displayed as a string. this will occur anywhere you call the funcion .ToString() on a float, int, or other object that supports the conversion.

avatar image KuPAfoo · Dec 03, 2013 at 09:29 PM 0
Share

Sweet! Very useful thanks!

Show more comments
avatar image
2

Answer by Owen-Reynolds · Dec 04, 2013 at 12:21 AM

The most common way is to add to any string, and let C# convert automatically:

 ""+score

ex: myGuiText.text = ""+score;

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

20 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Converting some C# pseudo code to UnityScript.... 1 Answer

How to import the object from server to unity 2 Answers

Terrain and heights arrays 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 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