You could try using a Vector3 and floats to define the size and distance of the Cast, and view how it will behave in the Scene view using OnDrawGizmos():
using UnityEngine;
using System;
public class YourScriptName : MonoBehaviour
{
[Header("Ground Detection")]
[SerializeField] float groundCheckRadius = 0.5f;//
[SerializeField] float groundCheckDistance = 1f;//
[SerializeField] Vector3 groundCheckPosition = new Vector3(0, -1, 0);//the position where the sphere cast starts
// you can remove this if its not needed
[SerializeField] LayerMask GroundLayer;// only these layers will be detected by the SphereCast, just to make sure the cast does not return true for something that is not the floor. set the layers on the inspector window
RaycastHit floor;
bool grounded;
void GroundCheck()
{
if (Physics.SphereCast(transform.position + groundCheckPosition, groundCheckRadius, Vector3.down, out floor, groundCheckDistance, GroundLayer))
{
//some code
grounded = true;
}
else
{
grounded = false;
//some code
}
}
private void OnDrawGizmosSelected()
{
// Line from where the cast starts to where it ends
Gizmos.DrawLine(transform.position + groundCheckPosition, transform.position + groundCheckPosition + Vector3.down * groundCheckDistance);
// sphere to show where the cast ends
Gizmos.DrawWireSphere(transform.position + groundCheckPosition + groundCheckPosition + Vector3.down * groundCheckDistance, groundCheckRadius);
//In case you want to check if the GroundCheck is working as intended on the editor
if (Physics.SphereCast(transform.position + groundCheckPosition, groundCheckRadius, Vector3.down, out RaycastHit tempHit, groundCheckDistance, GroundLayer))
{
Gizmos.color = Color.green;
// draws the wireSphere where the hit occurs
Gizmos.DrawWireSphere(transform.position + groundCheckPosition + groundCheckPosition + Vector3.down * tempHit.distance, groundCheckRadius);
}
}
}