-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDistancia.cs
42 lines (40 loc) · 1.18 KB
/
Distancia.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Distancia : MonoBehaviour
{
public Transform other;
public TextMeshProUGUI countText;
public GameObject winTextObject;
private float count;
private LineRenderer line;
void Start()
{
count = 0;
SetCountText();
winTextObject.SetActive(false);
// Add a Line Renderer to the GameObject
line = this.gameObject.AddComponent<LineRenderer>();
// Set the width of the Line Renderer
line.SetWidth(0.05F, 0.05F);
// Set the number of vertex fo the Line Renderer
line.SetVertexCount(2);
}
void Update()
{
if (other)
{
float dist = Vector3.Distance(other.position, transform.position);
count = dist;
SetCountText();
line.SetPosition(0, other.transform.position);
line.SetPosition(1, transform.position);
}
}
void SetCountText()
{
countText.text = "Distancia: " + count.ToString() + " metros";
winTextObject.SetActive(true);
}
}