40 lines
615 B
C#
40 lines
615 B
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class Waga : MonoBehaviour
|
|
{
|
|
public Rigidbody hookRbody;
|
|
|
|
[SerializeField]
|
|
private TextMeshPro textMesh;
|
|
|
|
private float _mass;
|
|
|
|
private Rigidbody _rbody;
|
|
|
|
private void Awake()
|
|
{
|
|
_rbody = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
public void SetText(float mass)
|
|
{
|
|
_mass = mass;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
float num = _mass * Mathf.Abs(1f - _rbody.linearVelocity.magnitude);
|
|
string text = num.ToString("F2");
|
|
if (num >= 10f)
|
|
{
|
|
text = num.ToString("F1");
|
|
}
|
|
if (num >= 100f)
|
|
{
|
|
text = Mathf.Round(num).ToString();
|
|
}
|
|
textMesh.text = text + " kg";
|
|
}
|
|
}
|