Version: 2019.4
public Collider collider ;

説明

ヒットしたコライダー

このプロパティーはレイが何にも当たらなかった場合は null になり、コライダーに当たった場合は null でなくなります。

using UnityEngine;

public class Example : MonoBehaviour { void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

if (Physics.Raycast(ray, out hit)) { if (hit.collider != null) { hit.collider.enabled = false; } } } } }