blob: ec7f469e92998bcad0c3e96e63ca973f06b99718 (
plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
using UnityEngine;
public class Looper : MonoBehaviour
{
private float sinceLoop = 1f;
private Camera mainCam;
private TrailRenderer trail;
private RayCastTrail rayTrail;
private int loops = 3;
private void Awake()
{
mainCam = MainCam.instance.transform.GetComponent<Camera>();
trail = base.transform.root.GetComponentInChildren<TrailRenderer>();
rayTrail = GetComponentInParent<RayCastTrail>();
}
private void Update()
{
if (loops <= 0 && sinceLoop > 0.3f)
{
Object.Destroy(this);
}
Vector3 vector = mainCam.WorldToScreenPoint(base.transform.position);
vector.x /= Screen.width;
vector.y /= Screen.height;
vector = new Vector3(Mathf.Clamp(vector.x, 0f, 1f), Mathf.Clamp(vector.y, 0f, 1f), vector.z);
if ((vector.x == 0f || vector.x == 1f || vector.y == 1f || vector.y == 0f) && sinceLoop > 0.1f)
{
if (vector.x == 0f)
{
vector.x = 1f;
}
else if (vector.x == 1f)
{
vector.x = 0f;
}
if (vector.y == 0f)
{
vector.y = 1f;
}
else if (vector.y == 1f)
{
vector.y = 0f;
}
vector.x *= Screen.width;
vector.y *= Screen.height;
base.transform.root.position = mainCam.ScreenToWorldPoint(vector);
rayTrail.MoveRay();
for (int i = 0; i < trail.positionCount; i++)
{
trail.SetPosition(i, base.transform.position);
}
sinceLoop = 0f;
loops--;
}
else
{
sinceLoop += TimeHandler.deltaTime;
}
}
}
|