動作環境
Unity 2018.2.9f1 Personal
Raycast関数の使い方
Raycastの呼び出し方
Physics.Raycast(Vector3 origin,Vector3 direction,out RaycastHit hitInfo, float distance, int LayerMask);
引数の概要
- origin: Rayの始点の座標
- direction: Rayの方向
- hitInfo: ヒットしたオブジェクトの情報
- distance(オプション): Rayの距離(default=Infinity)
- LayerMask(オプション): 指定したLayerのオブジェクトに特別な処理をさせる。(例: コリジョン判定を無視するなど)
Tip
第1引数及び第2引数を下記のように纏めて変数に格納し、代入する方法もあるよう。
Ray myRay = new Ray(Vector3 origin, Vector3 direction);
myRay = (始点となるオブジェクトのPosition)
Physics.Raycast(myRay,out RaycastHit hitInfo, float distance, int Layer Mask);