-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdgeTeleport.cs
34 lines (30 loc) · 994 Bytes
/
EdgeTeleport.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
using UnityEngine;
public class EdgeTeleport : MonoBehaviour {
float horzExtent;
private void Start()
{
horzExtent = Camera.main.orthographicSize * Screen.width / Screen.height;
}
void LateUpdate () {
if (transform.position.x > horzExtent + 0.1f)
{
Vector2 position = transform.position;
position[0] = -horzExtent;
transform.position = position;
if (GetComponentInChildren<TrailRenderer>())
{
GetComponentInChildren<TrailRenderer>().Clear();
}
}
else if (transform.position.x < -horzExtent - 0.1f)
{
Vector2 position = transform.position;
position[0] = horzExtent;
transform.position = position;
if (GetComponentInChildren<TrailRenderer>())
{
GetComponentInChildren<TrailRenderer>().Clear();
}
}
}
}