-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCamColliders.cs
More file actions
42 lines (31 loc) · 835 Bytes
/
CamColliders.cs
File metadata and controls
42 lines (31 loc) · 835 Bytes
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 UnityEngine;
public class CamColliders : MonoBehaviour
{
static Transform tform;
public static CamColliders instance;
public Transform bottom;
public Transform top;
public Transform right;
public Transform left;
public LayerMask collideMask;
void Awake()
{
instance = this;
tform = transform;
}
public bool isOutSideBox(Vector3 pos)
{
return Physics2D.Linecast(pos, tform.position, collideMask);
}
Vector3 FindPointInBox(Vector3 pos)
{
var rayDir = (pos - tform.position).normalized;
Ray ray = new Ray(tform.position, rayDir);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100, collideMask))
{
return hit.point + (-3 * rayDir);
}
return Vector3.zero;
}
}