GGJ2022/Assets/Scripts/UiController.cs

41 lines
1.0 KiB
C#
Raw Normal View History

2022-01-29 00:32:48 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class UiController : MonoBehaviour
{
public GameObject player = null;
private Vector3 startPosition;
private Vector3 playerPosition;
public TextMeshProUGUI uiDistance;
public float distance = 0.0f;
2022-01-29 10:54:13 +00:00
private float oldDistance = 0.0f;
2022-01-29 00:32:48 +00:00
// Start is called before the first frame update
void Start()
{
startPosition = this.player.transform.position;
2022-01-29 11:21:42 +00:00
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
2022-01-29 00:32:48 +00:00
}
// Update is called once per frame
void Update()
{
playerPosition = this.player.transform.position;
distance = Vector3.Distance(this.startPosition, this.playerPosition);
2022-01-29 10:54:13 +00:00
if (oldDistance < distance)
{
2022-01-29 11:21:42 +00:00
uiDistance.text = "Distance : " + distance.ToString("0");
2022-01-29 10:54:13 +00:00
oldDistance = distance;
}
2022-01-29 00:32:48 +00:00
}
2022-01-29 11:21:42 +00:00
//MENU
public void exitGame()
{
Application.Quit();
}
2022-01-29 00:32:48 +00:00
}