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
0
Question by Konkor4 · Oct 15, 2012 at 01:36 AM · stringscoreguitextint

Check if a guiText = a number?

The game I'm creating requires the player to collect a certain amount of objects each level, I want an endgame script that basically loads the score screen. How can I do this? When the player collects the objects they are displayed in a guiText, but I can't use

var object : guiText;

function Update(){ if(object.guiText.text = 2){ Application.loadlevel(0); } }

That's probably wrong but it was just a rough idea of what I was trying, it needs me to convert the string to int but I'm not sure how?

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 Konkor4 · Oct 15, 2012 at 01:52 AM 0
Share

Ah thanks, I was just thinking of adding to a separate script but it makes more sense to keep with the collection script.

Although if anyone tries this and gets an error try "LoadLevel(0)" ins$$anonymous$$d.

avatar image Seth-Bergman · Oct 15, 2012 at 02:08 AM 0
Share

yes true.. also, it's "GUIText" (guiText is a keyword for finding the GUIText component on an object.. so, in your example, theoretically, it would be like this:

var object : GUIText;

function Update(){

if(object.text == "2"){

Application.LoadLevel(0); }

}

OR

function Update(){

if(guiText.text == "2"){

... etc

2 Replies

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

Answer by Seth-Bergman · Oct 15, 2012 at 01:53 AM

if you are collecting a certain number of objects, then you should be keeping track of that as an int already.. then for the GUIText you would convert the int to a string. (You would never need to go from string to int in this case.) In order to keep track of the number of items collected it would need to be stored this way anyway. Here's a similar example:

http://answers.unity3d.com/questions/331921/collestion-of-objects.html

in this case, itemsCollected would be the int you are watching:

 function Update(){
  if(itemsCollected >= 2){
  Application.LoadLevel(0); }
  }

(for example)

(if you have an existing script to collect items, post it and I'll help fix it..)

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
0

Answer by sparkzbarca · Oct 15, 2012 at 01:54 AM

you can declare a char by placing it in single quotes or a string by placing it it double quotes

be aware

char = one character a character is basically a single keystroke, any key you can press is a character. one letter, one number, or symbols like !@#$.

string = a collection of characters

 'a' is a character
 '1' is a character
 
 "a" is a string
 "1" is a string
 "12" is a string
 12 is a int
 '12' is illegal, its two characters and a character is only one.

writing out the actual value is a literal string if you have say a string variable like

string my_own_string;

and its equal to only one character like

my_own_string = 'a';

and you'd like to convert it to a character tehre is a function for that

my_own_string.tochar();

hope taht helps mark as answered!

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

11 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

Related Questions

How do i link a GUI text to a variable text which is a integer? 2 Answers

I can't print a int.ToString() variable in a guiText.text 1 Answer

How to make GUI Text Scale to different Resolutions? 3 Answers

Extract number from string? 3 Answers

BCE0022: Cannot convert 'String' to 'int'. 0 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