36 lines
801 B
C#
36 lines
801 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Linq;
|
|
|
|
public class DebugSpeedometer : MonoBehaviour
|
|
{
|
|
public WheelPhysics[] wheels;
|
|
public Rigidbody car;
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
|
|
}
|
|
|
|
void OnGUI()
|
|
{
|
|
float speed_ms = 0;
|
|
if (wheels != null)
|
|
{
|
|
speed_ms = Mathf.Abs((float)wheels.Select(v => v.angularVelocity*v.TotalWheelRadius).Sum() / wheels.Length);
|
|
}
|
|
|
|
var speed_kmph = (speed_ms*60.0f*60.0f)/1000.0f;
|
|
var car_speed = car.velocity.magnitude*3.6f;
|
|
|
|
|
|
GUI.Label(new Rect(20, 100, 200, 40), "Wheels speed [km/h]: " + speed_kmph);
|
|
GUI.Label(new Rect(20, 140, 200, 40), "Real speed [km/h]: " + car_speed);
|
|
}
|
|
}
|