-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRaycast (Documentation).cs
31 lines (26 loc) · 1.35 KB
/
Raycast (Documentation).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
RaycastHit hit;
float detectAtDistance = 20.0f, unableToDetectAtDistance = 30.0f
void Update()
{
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, detectAtDistance))
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * detectAtDistance, Color.yellow);
Debug.Log("Did Hit");
}
else
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * unableToDetectAtDistance, Color.white);
Debug.Log("Did not Hit");
}
///////////////////////////////////////////////
if (Physics.Raycast(transform.position, transform.forward, out hit, 20) && hit.collider.gameObject.CompareTag("Object Tag Name Here"))
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 20.0f, Color.red);
Debug.Log("Did Hit");
}
else
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 20.0f, Color.white);
Debug.Log("Did not Hit");
}
}