Unity3D:RayCast碰撞检测

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wang_lvril/article/details/80630788

函数介绍:

static bool RayCast ( Vector3 orgin , Vector3 direction , out RayCastHit hitInfo , float distnace=Mathf.Infinity , int layerMask=DefaultRaycastLayers ) ;

  • 第一个参数为射线碰撞检测的原点;
  • 第二个参数为射线检测的方向矢量;
  • 第三个参数为out类型,用于得到碰撞检测的返回值;
  • 第四个参数为碰撞检测的射线长度;
  • 第五个参数为仅在指定层上碰撞检测

例子:

	Vector3 direction=target.transform.position-trnasform.position;
	RayCastHit hit;
	
	if(Physics.Raycast(transform.position,direction,out hit)){
		Debug.Log("碰撞对象:"+hit.collider.name);
	}

猜你喜欢

转载自blog.csdn.net/wang_lvril/article/details/80630788
今日推荐