I have driving simulator in which I’m trying to display a vehicle speed via a GUI Text controlled by a script.
In the vehicle controller script, I declare:
public GameObject vehicle; (this contains the RigidBody to get the speed)
public GUIText speedDisplay;
public float speedValue;
then in the update loop, I have:
speedValue = vehicle.GetComponent().velocity.magnitude;
speedDisplay.text = speedValue.ToString();
All of this seems to work fine, BUT THEN:
In the inspector while I can see my three variables and am able to drag my vehicle game object and see the speed value change at run time, Unity won’t let me drag any Text object from the hierarchy onto the GUI Text variable (the one that says Speed Display below and None (GUI Text) in the inspector.
My Text is part of a canvas and I’ve tried putting the text and canvas in different spots in the hierarchy with no success. I don’t know what I’m doing wrong. Any suggestions?
Thank you very much for your help.