I’ve looked around, but every question like this, seems to be related to the Rigidbody, or is asking for a way of displaying the speed onscreen rather than in console.
Basically I have this line of code:
transform.Translate (Input.GetAxis ("Horizontal") * Time.deltaTime * moveSpeed, 0f, Input.GetAxis ("Vertical") * Time.deltaTime * moveSpeed);
And I need to print the speed of the object for its local forward momentum (whatever direction it’s moving).
How do I?
Put a Unity UI Text object on screen, and drag a reference to it in your script:
(you need this at the top of your script file to access UI objects):
using UnityEngine.UI;
public Text SpeedDisplay; // drag your UI text object here.
Now in your script update loop, take the reference to your Rigidbody and output the velocity to the .text field of the Text UI object above.
myRigidbody = gameObject.GetComponent<Rigidbody>(); // (or however you already have it)
SpeedDisplay.text = myRigidbody.velocity.ToString();
You can supply formatting arguments to the .ToString() function. See google.