Scripted 3D Tachometer

I put this 3D tachometer together as part of a larger project.

Feel free to use or modify it for your own stuff.

A screenshot:

The package file:
683827–24572–$Tachometer00.unitypackage (3.53 MB)

The script:

using UnityEngine;
using System.Collections;

public class Tachometer : MonoBehaviour {

public Transform needle;//The needle object of the meter
	
	
public static float inputValue=0f;// The value provided by the player
public float inputMin=0f;// The minimum expected value for the meter's lowest reading
public float inputMax=0f;// The maximum expected value for the meter's highest reading
float inputTemp=0f;	//Temporary number
	
float currentReading=0f; // The angle of rotation for the needle object
public float minReading=0f;// The minimum angle of rotation for the needle object
public float maxReading=0f;// The maximum angle of rotation for the needle object
	
float testNum=0;// The number used to test the 
bool testTurn=true;// Used to cycle the test number
public bool testing=false;	//Are we testing?
	
	
	void Start()
	{
		if(testing)
		{
			testNum=inputMin;
		}else{
			inputValue=inputMin;
		}
	}
	
	void Update()
	{
		if(testing)
		{
			if(testTurn)
			{
				testNum=testNum+0.1f;
				if(testNum>=inputMax)
				{
					testTurn=false;
				}
			}else{
				testNum=testNum-0.1f;
				if(testNum<=inputMin)
				{
					testTurn=true;
					
				}
			}
		inputValue=testNum;
		}
	}	
	
	void FixedUpdate()
	{
		inputTemp = (inputValue - inputMin)/(inputMax - inputMin);  
	    currentReading = inputTemp*(maxReading - minReading) + minReading;    
	    needle.localRotation = Quaternion.Euler(new Vector3(0f,0f,currentReading));  		
	}


}

Does it actually read the rpm of the vehicle?

Its designed to display any float value you pass it, it can display rpm, speed, altitude, pressure, etc. To set it up to display RPM simply add the following line to your cars script.

Tachometer.inputValue=<your_cars_rpm>;

Or in the tachometer script add the following line.

inputValue=<your_cars_script>.<your_cars_rpm>;

Ensure that the inputMin and inputMax variables are set up to correctly receive the data. In this case inputMin would be zero and inputMax would be whatever the maximum value of the rpm is likely to be. If you go above or below these values the needle will simply stop at its input limits.

the package silently fails (bell rings) when attempting to import to unity 3.5.7f6.

do you know a solution for this or why it’s happening?