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:
24
Unity3D_RayCasts/Assets/Scripts/SphereCaster.cs
Normal file
24
Unity3D_RayCasts/Assets/Scripts/SphereCaster.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SphereCaster : MonoBehaviour
|
||||
{
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
float maxDistance = 10f;
|
||||
RaycastHit hit;
|
||||
|
||||
bool isHit = Physics.SphereCast(transform.position, transform.lossyScale.x / 2, transform.right, out hit,
|
||||
maxDistance);
|
||||
if (isHit)
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawRay(transform.position, transform.right * hit.distance);
|
||||
Gizmos.DrawWireSphere(transform.position + transform.right * hit.distance, transform.lossyScale.x / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
Gizmos.DrawRay(transform.position, transform.right * maxDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user