激光组件由这3个物体构成
就像这样,白色是gun、spawncast是射线、hit是碰撞判定点
在spawncast中加入linerenderer,并拖入下面的代码
private LineRenderer lineRederer;
- start
lineRederer = GetComponent<LineRenderer>();
lineRederer.enabled = true;
lineRederer.useWorldSpace = true;
- update
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.right);
Debug.DrawLine(transform.position, hit.point);
_monsters_id3.transform.position = hit.point;
lineRederer.SetPosition(0,transform.position);
lineRederer.SetPosition(1, _monsters_id3.transform.position);
//激光触碰到玩家
if (hit.collider.tag == "Player" )
{
//DOSTH
}
网友评论