Question by
shadowpuppet · Jun 18, 2017 at 08:59 PM ·
speedometer
speedometer -not a GUI- but an actual gameobject on car dash -SOLVED!!!
this is a gameobject on my boats dashboard with this script on the needle. it rotates wonderfully initially as I accellerate, but doesn't go back down when I slow down. I tried adding a keyup ( for when I stop accellerating) and going in the other direction but it was a fail. any ideas?
using UnityEngine;
using System.Collections;
namespace UnitySampleAssets.Vehicles.Car
{
public class speedOmeter : MonoBehaviour {
public float speed ;
MonoBehaviour boatSpeed;
public GameObject boat;
public Transform target;
public float damping = 2f;
void Awake () {
boatSpeed = boat.GetComponent<boatBank>();
}
void Update () {
speed = boatBank.boatSpeed;
transform.Rotate(0, 0, (-speed) * Time.deltaTime );
}
}
}
UPDATE*** seems it takes me to post here before I sort it out properly in my mind and come up with the answer. So here it is...I just don't care for a GUI speedometer because speed isn't really important but I wanted to have a working speedometer on the dash that simply rotates on it's Z axis to display speed - just to add life to the view
using UnityEngine;
using System.Collections;
namespace UnitySampleAssets.Vehicles.Car
{
public class speedOmeter : MonoBehaviour {
public float speed ;
public bool accellerating;
MonoBehaviour boatSpeed;
public GameObject boat;
public float damping = 2f;
void Awake () {
boatSpeed = boat.GetComponent<boatBank>();
}
void Update () {
if (Input.GetKeyDown(KeyCode.W))
accellerating = true;
if (Input.GetKeyUp(KeyCode.W))
accellerating = false;
speed = boatBank.boatSpeed;
if (accellerating == true)
transform.Rotate(0, 0, (-speed) * Time.deltaTime );
if (accellerating == false)
transform.Rotate(0, 0, (speed) * Time.deltaTime );
}
}
}
Comment