Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. public class DataCanvas : MonoBehaviour
  6. {
  7. [Header("References")]
  8. [SerializeField]
  9. private RotationController m_ship;
  10. [SerializeField]
  11. private Transform m_eyes;
  12. [SerializeField]
  13. private TextMeshProUGUI text;
  14. [SerializeField]
  15. private Canvas m_canvas;
  16. // Start is called before the first frame update
  17. void Start()
  18. {
  19. if (m_ship == null)
  20. m_ship = FindObjectOfType<RotationController>();
  21. }
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. RotationController();
  26. DisplayGravity();
  27. }
  28. public void RotationController()
  29. {
  30. Vector3 _directionToEyes = (transform.position - m_eyes.position).normalized;
  31. float _alignment = (Vector3.Dot(transform.forward, _directionToEyes) + 1)/2;
  32. float _backAngle = Vector3.Angle(_directionToEyes, transform.forward);
  33. float _rotationValue = Mathf.Lerp(180-_backAngle, 0, 0);
  34. //m_canvas.transform.localRotation = Quaternion.Euler(_rotationValue, 0, 0);
  35. //text.text = _alignment.ToString("0.00");
  36. }
  37. public void DisplayGravity()
  38. {
  39. float force = m_ship.GetGravityAtPoint(transform.position).magnitude;
  40. text.text = $"{force.ToString("0.00")} m/s";
  41. }
  42. }