mirror of
https://github.com/0015/ThatProject.git
synced 2026-01-12 09:17:42 +03:00
Unity3D | Tutorial | Raycast/Boxcast/Spherecast
This commit is contained in:
22
Unity3D_RayCasts/Assets/Scripts/RayCaster.cs
Normal file
22
Unity3D_RayCasts/Assets/Scripts/RayCaster.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class RayCaster : MonoBehaviour
|
||||
{
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
float maxDistance = 10f;
|
||||
RaycastHit hit;
|
||||
|
||||
bool isHit = Physics.Raycast(transform.position, transform.forward, out hit, maxDistance);
|
||||
if (isHit)
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawRay(transform.position, transform.forward * hit.distance);
|
||||
}
|
||||
else
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
Gizmos.DrawRay(transform.position, transform.forward * maxDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user