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 Kristopher Williams · Feb 17, 2011 at 12:12 PM · javascriptguifpsdistanceguitext

The next problem with gui.

Ok so heres my code from this section:

var Cam : Camera; public var distanceaway;

function Start() { distanceaway = 0; }

function OnGUI() { GUI.Label (Rect (10, 20, 100, 20), "distance: "+ distanceaway); }

function Update() { var ray = Cam.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; if (Physics.Raycast (ray, hit, 1000)) { distanceaway = hit.distance;
} }

When i run it occasionally it will display the distance but most of the time nothing is displayed after "distance: " just every now and then when scanning the environment itll flash up the distance. Any one got any ideas?

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

1 Reply

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

Answer by Alec-Slayden · Feb 17, 2011 at 12:17 PM

You currently have the ray length set to 1000 units. "Physics.Raycast (ray, hit, 1000)"

Objects without colliders, and objects beyond this distance of 1000 units will not register a collision, and therefore not report a distance. Hope that helps!

EDIT:

After checking out the script in game it looks like it was getting confused casting the number into string. I had the same flashing problem, but changing the GUI call to this:

GUI.Label (Rect (10, 20, 1000, 100), "distance: "+ distanceaway.ToString());

Seems to have fixed the problem, ensuring that distanceaway was interpreted as a string.

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 Kristopher Williams · Feb 17, 2011 at 12:21 PM 0
Share

the distances involved are all less than 1000. but thanks for the suggestion tho. I appreciate you taking the time to read my problem. just ran it and it flash up at summat like 42.98 and then at like 267.32. lol

avatar image Alec-Slayden · Feb 17, 2011 at 12:49 PM 0
Share

You're welcome. I think changing the distanceaway to a string through operation will help

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

What's wrong with my function? It keeps telling me 'loseText' is not a member of 'UnityEngine.GUIText'. Please help, please and thank you! 0 Answers

Create GUIText from Javascript 3 Answers

Using AutoType script on GUI.Label? 1 Answer

How do I change the text of a gui image text 1 Answer

Distance on fps 3 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