• 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 rickaz · Jan 20, 2013 at 02:51 AM · c#rotationangleobject position

Object position to player position in angle and apply to rotating a gui plane?

 Hello All

 I have the idea to c# script a Player directional indicator, but have know
 idea where to start.

 Plan:

 object 1 - A standard prefab cube as a target to witch the script will apply.

 object 2 - The player, after all, the indicator will help him find his goal.

 object 3 - A plane with transparency texture symbolizing an arrow on screen,
 using a other stationary objects created as a HUD with it's own off player
 camera. (set under the terrain.)

 I need to take a angle from player to target, get the result. Then convert that
 result to rotational movement in degree, and apply it to rotate the indicator's
 plane.

 good in ideas, but not in execution.

using UnityEngine; using System.Collections; public class Target_Indicator : MonoBehaviour { public Transform target; //values that will be set in the Inspector. public float angle = 0; //Create sting, Now we can see it in the inspector. void Update() { Vector3 targetDir = target.position - transform.position; Vector3 forward = transform.forward; float angle = Vector3.Angle(targetDir, forward); } void OnGUI() { float displayValue = Mathf.Round(angle);//Change decimal to hole numbers. //Make a GUI label - position on sccreen - add "angle:" - display the value. GUI.Label(new Rect(30, 475, 150, 50), "angle: " + displayValue.ToString()); } }

 This should at lest give the angle and place on screen, but it through an error:

 Assets/Scripts/Target_Indicator.cs(13,16): warning CS0219: The variable `angle' is assigned but its value is never used

 any help would be appreciated.

 Rick 
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Flip over an object (smooth transition) 3 Answers

Getting the rotation of an object does not return correct rotation 1 Answer

Multiple Cars not working 1 Answer

How do I rotate the hook? 1 Answer

Having Trouble with Vector3.Angle 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