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 CosmicHD3 · Jul 25, 2014 at 12:54 AM · javascriptguicompassadventure

Compass Bar GUI Help!

I need some help with making a compass gui. Not like the standard circular GUI though. One that scrolls and looks like this: (It's Horrible, sorry. Hopefully you get what I mean)

alt text

Anyways, I've tried to do different ways and it never works. Can anyone help please? :)

Thank you!

compass.png (2.7 kB)
compass.png (2.7 kB)
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
2

Answer by robertbu · Jul 25, 2014 at 05:37 AM

Here is a quick example. First you need to use this texture:

alt text

It takes the angle from a target object. It is currently setup so that Vector3.forward is north making Vector3.right east, Vector3.left west, and Vector3.back south.

 #pragma strict
 
 var target : Transform;
 var compassTex : Texture;
 
 private var displayRect : Rect;
 private var texRect : Rect = Rect(0,0,3.0/8.0, 1.0);
 var factor = 1.0;
 
 function Start() {
     displayRect = Rect(Screen.width / 2 - 400, 10, 300, 32);
 }
 
 function OnGUI() {
     var angle = Mathf.Atan2(target.right.z, target.right.x) * Mathf.Rad2Deg;
     texRect.x = 5.0 / 16.0 + angle / 90.0 / 8.0;
     GUI.DrawTextureWithTexCoords(displayRect, compassTex, texRect);
 }

I designed the long graphic so that the code did not depend on the graphic wrapping. If you are sure that the devices you are going to use support wrap mode for images, then you could significantly shorten this image. Plus I probably made it longer than necessary even for a non-wrapping solution.

This is a quick example with code that is highly dependent on the graphic I've used. It could easily be generalized, but I leave that to you.


compass.png (4.9 kB)
Comment
Add comment · Show 3 · 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 CosmicHD3 · Jul 25, 2014 at 03:18 PM 0
Share

Alright, thanks :P

avatar image CosmicHD3 · Jul 25, 2014 at 04:37 PM 0
Share

It works dude, thanks so much! :D

avatar image robertbu · Jul 25, 2014 at 04:39 PM 0
Share

You are looking for more solutions to this problem in your other question. This concept (essentially sliding the material offset and the material scale) can be done with a world space object ins$$anonymous$$d of using GUI.DrawTextureWithTexCoords(). You can use $$anonymous$$aterial.mainTextureOffset and $$anonymous$$aterial.mainTextureScale. And for a different look, you could implement a cylinder with directions on the side probably viewed using an Orthographic camera. The cylinder would be rotated to match the camera direction. You could also do it using text output (GUI.Label, GUIText or 3D Text) and modifying the position and visibility of the text based on the rotation. I think the last would be a bit more complicated than what I've done above.

avatar image
0

Answer by jmgek · Jul 25, 2014 at 01:53 AM

Just have a plane with that width and height and put that exact texture on it.

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 CosmicHD3 · Jul 25, 2014 at 03:15 AM 0
Share

That doesn't make it animated though. I want it to move like a compass. That picture was just an example :D

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Gui Text Script 4 Answers

GUI Button Disappearing 1 Answer

GUI.Box NullReferenceException 0 Answers

How do I use a trigger to change the GUIText 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