Hey, Im having some issues with rotating GUI.
I have a radar, and above that is a green sweeper thing that should rotate directly over the radar's GUI, Ive tried a few methods so far, and this has been the closest to working.
This main problem is that it finds the pivot of the GUI using X,Y as-well - this causes the thing to spin round in totally off ways at some resolutions, how can i correct my code to make it use a pivot that only relates to the texture?
public var testTexture: Texture2D = null;
var centerObject : Transform;
var mapScale = 0.3;
var mapSizePercent = 15;
enum sweepLocationValues {topLeft, topCenter, topRight, middleLeft, middleCenter, middleRight, bottomLeft, bottomCenter, bottomRight, custom}
var sweepLocation : sweepLocationValues = sweepLocationValues.bottomLeft;
private var mapWidth : float;
private var mapHeight : float;
private var mapCenter : Vector2;
var mapCenterCustom : Vector2;
function Start () {
setMapLocation();
}
function OnGUI(){
//Here comes the tachoneedle rotation
var matrixBackup:Matrix4x4 = GUI.matrix;
var thisAngle:float = Time.frameCount * 2;
var pos:Vector2 = Vector2(50,830); // rotatepoint in texture plus x/y coordinates. our needle is at 16/16. Texture is 128/128. Makes middle 64 plus 16 = 80
GUIUtility.RotateAroundPivot(thisAngle, pos);
bX=centerObject.transform.position.x * mapScale;
bY=centerObject.transform.position.z * mapScale;
GUI.DrawTexture(Rect(mapCenter.x - mapWidth/2,mapCenter.y-mapHeight/2,mapWidth,mapHeight),testTexture);
GUI.matrix = matrixBackup;
}
function setMapLocation () {
mapWidth = Screen.width*mapSizePercent/100.0;
mapHeight = mapWidth;
//sets mapCenter based on enum selection
if(sweepLocation == sweepLocationValues.topLeft){
mapCenter = Vector2(mapWidth/2, mapHeight/2);
} else if(sweepLocation == sweepLocationValues.topCenter){
mapCenter = Vector2(Screen.width/2, mapHeight/2);
} else if(sweepLocation == sweepLocationValues.topRight){
mapCenter = Vector2(Screen.width-mapWidth/2, mapHeight/2);
} else if(sweepLocation == sweepLocationValues.middleLeft){
mapCenter = Vector2(mapWidth/2, Screen.height/2);
} else if(sweepLocation == sweepLocationValues.middleCenter){
mapCenter = Vector2(Screen.width/2, Screen.height/2);
} else if(sweepLocation == sweepLocationValues.middleRight){
mapCenter = Vector2(Screen.width-mapWidth/2, Screen.height/2);
} else if(sweepLocation == sweepLocationValues.bottomLeft){
mapCenter = Vector2(mapWidth/2, Screen.height - mapHeight/2);
} else if(sweepLocation == sweepLocationValues.bottomCenter){
mapCenter = Vector2(Screen.width/2, Screen.height - mapHeight/2);
} else if(sweepLocation == sweepLocationValues.bottomRight){
mapCenter = Vector2(Screen.width-mapWidth/2, Screen.height - mapHeight/2);
} else if(sweepLocation == sweepLocationValues.custom){
mapCenter = mapCenterCustom;
}
}
This is the flawed function...i think.
function OnGUI(){
//Here comes the tachoneedle rotation
var matrixBackup:Matrix4x4 = GUI.matrix;
var thisAngle:float = Time.frameCount * 2;
var pos:Vector2 = Vector2(50,830); // rotatepoint in texture plus x/y coordinates. our needle is at 16/16. Texture is 128/128. Makes middle 64 plus 16 = 80
GUIUtility.RotateAroundPivot(thisAngle, pos);
bX=centerObject.transform.position.x * mapScale;
bY=centerObject.transform.position.z * mapScale;
GUI.DrawTexture(Rect(mapCenter.x - mapWidth/2,mapCenter.y-mapHeight/2,mapWidth,mapHeight),testTexture);
GUI.matrix = matrixBackup;
}
What i would like todo, is have it take its coordinates like my radar script does, but then rotate around its own private axis - if that makes sense.
But i cant seem to get it right here,
var pos:Vector2 = Vector2(50,830);
I would really appreciate any help you could give me with this, its driving me insane!
Thankyou,
//" - Graeme."