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 getyour411 · Sep 01, 2013 at 05:25 AM · scrollinghorizontalcompass

Horizontal scrolling style compass

How do I setup a horizontal scrolling style compass that turns with my player?

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

3 Replies

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

Answer by getyour411 · Sep 01, 2013 at 05:27 AM

I've seen a few requests for this and the other day came across a code snippet that gave me an idea on how to add this to my game. The result is below. There's probably a more efficient way to get some of that out of OnGUI(), if I find it or see suggestions for improvement I'll update this:

 /// <summary>
 /// Simple horizontal style compass for 3D world
 /// Attach this to your Player. 0 degrees is North. 
 /// Adjust if your orientation is different by changing the letters.
 /// Use/modify anyway you like.
 /// </summary>
 
 using UnityEngine;
 using System.Collections;
 
 public class QM_Compass : MonoBehaviour {
     
     // Feel free to set these all to private once you are done tweaking:
     private Transform myTransform;
     public int facingDir;
     public int degreeOffset;
 
     void Start () {
         myTransform = transform;
     }
     
     // Minor adjustments from 0,90,180,270 due to Font width
     // Adjust letter offset to match your Font size/width
     
     void OnGUI() {
         
         if(degreeOffset > -85 && degreeOffset < 90) {
             GUI.Label( new Rect((Screen.width/2)-degreeOffset*2,
             (Screen.height)-50,
             180,
             25),
             "N");
         }
         
         if(degreeOffset > 5 && degreeOffset < 180) {
             GUI.Label( new Rect((Screen.width/2)-degreeOffset*2+180,
             (Screen.height)-50,
             180,
             25),
             "E");
         }    
         
         if((facingDir > 95 && degreeOffset> 95) || (facingDir < 276 && degreeOffset < -90)) {
             GUI.Label( new Rect((Screen.width/2)-facingDir*2+360,
             (Screen.height)-50,
             180,
             25),
             "S");    
         }
         
         if((facingDir > 186 && degreeOffset < -5)) {
             GUI.Label( new Rect((Screen.width/2)-facingDir*2+540,
             (Screen.height)-50,
             180,
             25),
             "W");
         }
         
         GUI.Box( new Rect((Screen.width/2)-180,
             (Screen.height)-65,
             360,
             35),
             "Heading");
     }
     
     void Update () {
         
         facingDir = (int)Mathf.Abs(myTransform.eulerAngles.y);
         if (facingDir > 360) facingDir = facingDir % 360;
                 
         degreeOffset = facingDir;
         
         if(degreeOffset > 180) degreeOffset = degreeOffset - 360;
         
     }
 }
Comment
Add comment · Show 1 · 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 R0RAGS · Sep 13, 2017 at 07:45 PM 0
Share

hi i am using your script right now but i would like to make the compass fit to any resolution how do i do that

avatar image
0

Answer by DaiMangouDev · Sep 04, 2015 at 10:18 PM

This is really old but .

This can work for you , a paid tool. https://www.assetstore.unity3d.com/en/#!/content/33770

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 R0RAGS · Sep 14, 2017 at 07:02 PM

hi i am using your script right now but i would like to make the compass fit to any resolution how do i do that.

@getyour411

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

18 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

Related Questions

How do I add a scrolling input text box in an EditorWindow? (more info added) 1 Answer

Offset of texture with Raycast 1 Answer

How to go to a specific item in a scrollable list 0 Answers

Unity 2D scrolling camera constantly 1 Answer

scrollview scrolling don't work with event trigger 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