Display rigidbody speed to a world space canvas text
Im trying to display the speed value given by this script to a world space canvas as just text but I cant for the life of me figure out how heres my speed code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class speed : MonoBehaviour {
void Update () {
var speed = GetComponent<Rigidbody>().velocity.magnitude;
Debug.Log("speed:" + GetComponent<Rigidbody>().velocity.magnitude + "m/s");
}
}
Help would be much appreciated
Comment
Best Answer
Answer by exzizt · Mar 24, 2018 at 04:47 AM
Add a Text component to your scene.
Get a reference to this Text component. E.g.: Add a "public Text myText;" and serialize it using the scene editor.
After "var speed = ...", have "myText.text = speed.ToString();" Done.