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;

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! :/

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)

by the way thanyou sir :)

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

2 Answers

2

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

""+score

ex: myGuiText.text = ""+score;

float myNumber = 0.8f;

void Start()
{
    Debug.Log(myNumber.ToString());
}

works for me

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!")) { HighScoreManager._instance.SaveHighScore(name,System.Int32.Parse(score)); highscore = HighScoreManager._instance.GetHighScore(); Application.LoadLevel("Main_Menu"); }

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 }

That converts only in debug?

Sweet! Very useful thanks!

don't forget to mark the question as answered if your problem is solved