Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Adam Bruns · Mar 02, 2010 at 03:23 AM · errorstringjavascript-specifictostring

Convert Float to String? or 3D Text = Float?

(note: it may be an Integer not a float, im not quite sure) so in my "RPG game" i'm setting up a very simple click to auto attack system, so far i have this set up on my monster:

var hitPoints = 100.0;
var Player: Transform;
var Self: Transform;
var TextofMonster: Transform;

function OnMouseOver () {
if (Input.GetMouseButtonDown(1)) {
Player.GetComponent(AttackSomething).AttackMonster(Self);

}
}

function ApplyDamage(DamageofWeapon) {
print(DamageofWeapon);

 hitPoints -= DamageofWeapon;<br>

TextofMonster.GetComponent(TextMesh).text = "DamageofWeapon";
if (hitPoints {

     DestroySelf();<br>
 }<br>

}

function DestroySelf()
{
print("destroy")
}

now the DamageofWeapon is an Float sent from another script, its a random number (depending on what weapon you use). I have the TextofMonster set up as a 3d Text that is a child of the monster, and it's original text is set to a space (nothing). I want it so everytime the function is called, it shows the damage that is caused (the DamageofWeapon) but i tried just putting that in there but i get an error code. I figure this is because DamageofWeapon is an Float and not a String, so alas my question, can i turn the number from DamageofWeapon into a string, or make the 3D text display that Float?

Comment
Add comment
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

2 Replies

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

Answer by Eric5h5 · Mar 02, 2010 at 04:02 AM

Use .ToString():

var someNumber = 10.5;
GetComponent(TextMesh).text = someNumber.ToString();
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
avatar image
1

Answer by Ashkan_gc · Mar 02, 2010 at 07:21 AM

all classes in .NET/MONO has a method called ToString that returns a string representing the value of that class. you can override that class for your own classes too. let's say you have a point class then you can write

class point
{
public float x;
public float y;
override string ToString ()
{
return x.ToString () + " , " + y.ToString ();
}

you can use this function to create great strings that help in debugging your game. if you don't create a function yourself it will return the class name. to convert back string to float,double, int you can use int.Parse (yourstring) or float.Parse (yourstring)

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

No one has followed this question yet.

Related Questions

Convert Int to String? 1 Answer

Part of string not showing 1 Answer

Unity says that my script isn't doing anything? 1 Answer

while passing to a function in Prime31 throws error 1 Answer

Operator '==' can't be applied by operands Text and String 2 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