- Home /
Integer to Character in unityscript
I'm trying to save alot of integers into a string, this time in javascript (unityscript). This was a fairly easy thing to do with C# and the ability to cast variable types:
class Example : MonoBehaviour{
int id = 5;
string id_list;
void Awake(){
id_list += (char)id;
Debug.Log(id_list);
}
}
That returns ♣. How do I go about returning ♣ in unityscript?
For future reference - it's best to google things like "Convert an int to a char .NET" and then work out what the Unity Script version of that code would be.
Annoying I know, but often no point googling this kind of thing with the keyword Javascript - it's just too different.
Answer by ArkaneX · Sep 27, 2013 at 08:01 PM
If you want to cast an int to char, then you can use
var c : char = id;
or
var c : char = System.Convert.ToChar(id);
Please note, that this will not show in console (and I believe in GUI too). Instead, if you want to display clubs character, use its Unicode character. In C# you would assign it as:
var c = '\u2663';
while in UnityScript use:
var c : char = System.Convert.ToChar(0x2663); // 0x because it's hexadecimal
Small edit: of course var c : char = 0x2663;
should work as well...
Or just var c : char = "♣"[0];
rather than arcane number codes. ;) It will display fine.
Answer by perchik · Sep 27, 2013 at 07:20 PM
Have googled it? There are no good results. Please leave something constructive.
I call shenanigans. I am 100% sure that you have not tried to convert your code to unityscript and you want us to do it for you.
If you have used unity javascript at all, then creating new variables is trivial. So is writing an Awake function in javascript. To add an integer to a string in javascript is also trivial, but perhaps the syntax is new to you, but that's easy to find by a quick google search
You do realised that your L$$anonymous$$GTFY returns results for real Javascript that would be totally useless in Unity right?
If you were to modify it to use Unity Script you would find no immediately useful results and this question is in position 3.
How about giving a simple example ins$$anonymous$$d of telling everyone to google everything lol. It's not like UA is a google redirect, and I'd rather people come here than google, just saying...
Your answer
Follow this Question
Related Questions
C# to Java Script Conversion 2 Answers
Distribute terrain in zones 3 Answers
C# conversion of JavaScript, problems with nested class as a custom type 1 Answer
java to C# conversion 1 Answer
C#, Rigidody, Javascript Tutorial 1 Answer