Speedo ... of dooom!

Hello!

So, my speedo works and it works well … in only one aspect ratio / resolution. When I try to change res or ratio, things get really nasty!

I was thinking that hack no.1 would be to hard-code position and scale per resolution, so easssentially have a bunch of settings for every resolution I can think of. That’s pretty ikky.

I’d love to solve this properly, but the whole matrix thing is beyond my tiny mind and I just don’t see how I can … if you can help, I’d be super-grateful!

I’m using the (mighty!) Duck’s code from UnityAnswers … note this is the base code and I’ve taken out any failed attempts at making it scale!

ANY ideas on making a speedo needle rotate nicely in different resolutions would be REALLY welcome :slight_smile:

using UnityEngine;
[ExecuteInEditMode()] 
public class drawSpeedo : MonoBehaviour {
	
    public Texture2D speedoTexture = null;	
    public Texture2D texture = null;
    public float angle = 0;
    private Rect sRect;
    private Vector2 pivot;
		
    void OnGUI() {
		
		GUI.DrawTexture(new Rect(Screen.width/2+165,Screen.height-144,128,128), speedoTexture);
			
		Matrix4x4 matrixBackup  = GUI.matrix;
		Vector2 pos1 = new Vector2(Screen.width/2+173+64,Screen.height-134+64); 
		GUIUtility.RotateAroundPivot(angle-95, pos1);
		sRect = new Rect(Screen.width/2+173,Screen.height-134,128,128);
		GUI.depth = -6;
		GUI.DrawTexture(sRect, texture);
                GUI.matrix = matrixBackup;

    }
}

I would model a speedometer using standard 3D objects, so the question would become moot. :slight_smile:

–Eric

Yeah, ya know what? I’ve been toying with that idea since day 1 and for the amount of hassle this GUI-based idea is causing, maybe it’s time I gave it a try. If you don’t have a quick answer, that would suggest that there’s no real quick solution :slight_smile:

Cheers!

I just switched over to a 3d-based speedo on a separate camera- It was so much easier!

You know how easy it is to over complicate things when there’s a much easier solution that would take just ten or twenty minutes to implement? Done. For some reason, I’d gotten obsessed with the idea of keeping everything in GUI code. Silly me!

Cheers!