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
1
Question by Benifir · Aug 28, 2013 at 09:56 AM · c#compassgui.boxtostring

Help with GUI.Box Problem?

I am creating a FPS-TPS Framework/Starter Kit and decided to come to you after my search in the docs failed. My compass script is displaying odd. It has two values like two boxes are sharing the same Rect. Here is an image as well as the script. Thanks for the help!

alt text

And the script. Its fairly basic so I assume it has something to do with the way Unity works internally. And yes, it is a modified version found on the UnityWiki. using UnityEngine; using System.Collections;

 public class Compass : MonoBehaviour {
     public float updateFreq = 1.0f;
 
     private float _heading = 0.0f;
     private string _headingString;
 
     private Transform _gpsRef;
     private float _gpsRefN;
     private float timer = 0.0f;
 
     public bool debug = false;
 
     // Use this for initialization
     void Start () {
         Init();
     }
     
     // Update is called once per frame
     void Update () {
         FindHeading();
     }
 
     void Init() {
         GameObject gpsRefGameObject = GameObject.FindGameObjectWithTag("GPSRef");
         if(debug)Debug.Log("GPSReference: " + gpsRefGameObject);
         
         if(gpsRefGameObject = null)
             Debug.LogError("There is no GameObject named GPS Reference");
         else if(gpsRefGameObject != null)
             if(debug)Debug.Log("There is a GPS Reference GameObject");
         else
             if(debug)Debug.Log("There is something stored as GPS Reference");
     
         if(gpsRefGameObject != null) {
             _gpsRef = gpsRefGameObject.transform;
             _gpsRefN = _gpsRef.rotation.eulerAngles.y;
         }
     }
 
     void OnGUI() {
         DisplayCompass();
     }
 
     public void FindHeading() {
         timer += Time.deltaTime;
         _heading = transform.rotation.eulerAngles.y - _gpsRefN;
         
         if(_heading < 0)_heading += 360;
         
         if(timer > (1 / updateFreq)) {
             timer = 0;
         }
         
         _heading = Mathf.Round(_heading * 1f) / 1f;
         _headingString = _heading.ToString() + " deg";
         
         if(debug)Debug.Log(transform.rotation.eulerAngles.y + " - " + _gpsRefN + " = " + _heading);
     }
 
     public void DisplayCompass() {
         GUI.Box(new Rect((Screen.width / 2) - 100, 20, 100, 25), _headingString);
     }
 }
 
untitled.png (316.3 kB)
Comment
Add comment · Show 3
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 Benifir · Aug 30, 2013 at 10:20 AM 0
Share

Bump

avatar image Benifir · Aug 30, 2013 at 01:53 PM 0
Share

You sir, are a god. This has been a problem for a couple days, I just found a duplicate component attached to the terrain for some reason.

avatar image robhuhn · Aug 30, 2013 at 01:59 PM 0
Share

oki, I changed the comment to an answer.

1 Reply

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

Answer by robhuhn · Aug 30, 2013 at 01:48 PM

The script is definitely attached to only one gameObject in the scene? Does it flicker so may be _headingString is jumping from high values to low values immediately?

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

16 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How do I make onMouseDown work for OnGUI in C#? 1 Answer

how to listing all game objects in GUI.Box? 1 Answer

How to Display only current instead of current/max on a GUI.Box 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