- Home /
How to make the arrow to follow the character's moving in minimap?
The character's moving direction should be showed in the minimap by a arrow(texture),so how can I make the arrow's direction to follow the character?
Answer by aldonaletto · Mar 20, 2012 at 01:09 PM
You must use GUIUtility.RotateAroundPivot: this function modifies the GUI matrix to draw GUI elements rotated at the specified angle around the pivot point.
Find the pivot point in GUI screen coordinates (y=0 means top), and set the angle based on the character forward direction:
var arrow: Texture2D; // drag the arrow texture here
var rArrow: Rect(10, 10, 110, 110); // rectangle where to draw the arrow
function OnGUI(){
var svMat: Matrix4x4 = GUI.matrix; // save the current GUI matrix
// find the pivot and rotation angle:
var pivot = rArrow.center; // get the arrow center point
var ang = transform.EulerAngles.y; // get the character angle
// set GUI matrix to rotate ang degrees around the pivot:
GUIUtility.RotateAroundPivot(ang, pivot);
GUI.DrawTexture(rArrow, arrow); // draw the arrow
GUI.matrix = svMat; // restore the matrix to not affect other GUI items
}
Hey Aldo
Thanks for this answare.
Do you have this as sampel poject?
Your answer
Follow this Question
Related Questions
Show object location with arrow 1 Answer
transform.position innacurate? [Unity 2D] 1 Answer
Minimap North Direction 1 Answer
Displaying Objective Points Through GUI. 2 Answers
Local Direction of Vector3 1 Answer