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
2
Question by ForgeStudios · Sep 27, 2013 at 07:17 PM · c#javascriptsystemconversion

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?

Comment
Add comment · Show 2
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 whydoidoit · Sep 27, 2013 at 09:16 PM 0
Share

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.

avatar image ForgeStudios · Sep 28, 2013 at 02:23 AM 0
Share

I'll keep that in $$anonymous$$d.

2 Replies

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

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

Comment
Add comment · Show 2 · 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 Eric5h5 · Sep 27, 2013 at 10:21 PM 4
Share

Or just var c : char = "♣"[0]; rather than arcane number codes. ;) It will display fine.

avatar image ForgeStudios · Sep 28, 2013 at 02:22 AM 1
Share

Thank you very much!

avatar image
-2

Answer by perchik · Sep 27, 2013 at 07:20 PM

http://lmgtfy.com/?q=convert+integer+to+string+javascript

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 ForgeStudios · Sep 27, 2013 at 07:31 PM 0
Share

Have googled it? There are no good results. Please leave something constructive.

avatar image perchik · Sep 27, 2013 at 07:38 PM 0
Share

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

avatar image ArkaneX · Sep 27, 2013 at 08:04 PM 3
Share

OP needs converting to char, not string.

avatar image whydoidoit · Sep 27, 2013 at 09:14 PM 5
Share

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.

avatar image clunk47 · Sep 27, 2013 at 09:50 PM 4
Share

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

Show more comments

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

21 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 avatar image

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


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