initial commit
This commit is contained in:
27
Assets/Scripts/Lesson_2/WaterLevelController.cs
Normal file
27
Assets/Scripts/Lesson_2/WaterLevelController.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
public class WaterLevelController : MonoBehaviour
|
||||
{
|
||||
public TextMeshPro waterLevelText;
|
||||
public TextMeshPro cubeMassText;
|
||||
|
||||
private float waterLevel = 100f;
|
||||
public float currentCubeVolume = 0f;
|
||||
public float currentCubeMass = 0f;
|
||||
|
||||
void Update()
|
||||
{
|
||||
waterLevelText.text = "WATER VOLUME " + (waterLevel + currentCubeVolume).ToString().Replace(",", ".") + "L";
|
||||
cubeMassText.text = "OBJECT MASS " + currentCubeMass.ToString().Replace(",", ".") + "KG";
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.gameObject.tag != "DensityCube") return;
|
||||
|
||||
DensityCube dc = other.GetComponent<DensityCube>();
|
||||
currentCubeVolume = dc.cubeVolume;
|
||||
currentCubeMass = dc.mass;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user