-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAntBar.cs
43 lines (32 loc) · 1.05 KB
/
AntBar.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
43
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AntBar : MonoBehaviour
{
RectTransform rt;
Transform tr;
public float upPoint;
public float downPoint;
public float barLength;
float Ant2Dx, Ant2Dy, Ant2Dht, curAntPosition, treeLength, curLength, ratio, plusLength;
// Start is called before the first frame update
void Start()
{
treeLength = upPoint - downPoint;
rt = (RectTransform)gameObject.transform;
tr = GameObject.Find("ant").GetComponent<Transform>();
Ant2Dx = rt.localPosition.x;
Ant2Dy = rt.localPosition.y;
Ant2Dht = rt.rect.height;
barLength -= Ant2Dht;
ratio = barLength / treeLength;
}
// Update is called once per frame
void Update()
{
curAntPosition = tr.position.y;
curLength = curAntPosition - downPoint;
plusLength = curLength * ratio;
rt.anchoredPosition = new Vector2(Ant2Dx, Ant2Dy + plusLength);
}
}