At present,I am using the System namespace to Convert class to complete this function…
using UnityEngine;
using System.Collections;
using System; //useing this namespace
......
void Move(string x_in, string y_in, string z_in)
{
Vector3 Translate_temp = new Vector3((float)Convert.ChangeType(x_in, typeof(float)), (float)Convert.ChangeType(y_in, typeof(float)), (float)Convert.ChangeType(z_in, typeof(float)));
transform.position = Translate_temp;
}
I would like to ask, there are other way? Functional categories related to it in unity?
Thank you
base type conversion is fully handled by the .NET end. Unity does not offer extra functionality to that, as the .NET core offers all required conversion routes from numeric to string and vice versa and all of them to bytearray and alike
But for some reason I’m pretty sure that there are shorter versions of what you have there in .NET through the Single and String class and alike
To cast a string to float, i use this:
string myString = "15.5";
float number = (float) int.Parse(myString);
float num = System.Convert.ToSingle( myString );
O, Thank you Shaneo and lehk
I think the “float number = float.Parse(myString);” is good
Because they does not need System of NameScape…