UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"give me an example of a raycast hit and no hit in the same method"
public class RaycastExample : MonoBehaviour { public GameObject player; void FixedUpdate() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask)) { Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.red); Debug.Log("Did Hit"); } else { Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white); Debug.Log("Did not Hit"); } } }