- Home /
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
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Multiple Cars not working 1 Answer
How do i determin if an objects rotation is between 2 values on each axis? 0 Answers
Rotate angle 0 Answers