using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RevCounterDisplay : MonoBehaviour {

	public float _revCount;
	public GameObject RevCounterNeedle;
	public GameObject CentrePoint;
	[Range(0,8000)]
	public float RevCount;
	private float _previousRev;
	private float _newRev;

	private float _previousAngle;
	private float _newAngle;
	private float dir;
	public float Divisor;

	void Awake()
	{
		CentrePoint.transform.position = this.gameObject.GetComponent<Renderer> ().bounds.center;
		_previousRev = RevCount;
	}

	public void SetNeedleAngle()
	{
		_newRev = RevCount;
		_newAngle = _newRev - _previousRev;
		dir = _newAngle - _previousAngle;
		UpdateRevCounterPos ();
		_previousRev = _newRev;
	}

	void UpdateRevCounterPos()
	{
		RevCounterNeedle.transform.RotateAround(CentrePoint.transform.position, Vector3.forward, -dir/Divisor);
	}
	void Update()
	{
		SetNeedleAngle ();
	}
}
