用于判断物理查询形状与检测到的 Collider2D 表面相交的世界空间位置。
using UnityEngine;
public class ExampleClass : MonoBehaviour { public Vector2 direction;
void Update() { // Cast a ray in the direction specified in the inspector. RaycastHit2D hit = Physics2D.Raycast(transform.position, direction);
// If something was hit, draw a line from the start position to the point we intersected. if (hit) Debug.DrawLine(transform.position, hit.point, Color.yellow); } }