xxxxxxxxxx
// Raycast Example 4: Spherecast for Object Detection
// Description: This code performs a spherecast from the object's position to detect nearby objects.
// Date: 2023-10-12
using UnityEngine;
public class Print : MonoBehaviour
{
public float radius = 1f; // Radius of the spherecast.
void Update()
{
// Perform a spherecast from the object's position to detect nearby objects.
RaycastHit hit;
if (Physics.SphereCast(transform.position, radius, transform.forward, out hit))
{
// Log the name of the detected object.
Debug.Log("Spherecast hit: " + hit.transform.name);
}
}
}