老师,我用的UGUI写的黑暗之光,但是鼠标在点击UI的同时人物还会移动,加了判断UI标签的代码但还是会移动
怎么样才能不让射线与UI发生碰撞
我代码是写在这里的 控制人物方向发射射线的地方
void Update ()
{
if (Input.GetMouseButtonDown (0))
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hitInfo;
bool isCollder = Physics.Raycast(ray,out hitInfo);
//LayerMask mask = 1 << LayerMask.NameToLayer ("UI");
if (isCollder && hitInfo.collider.tag == Tags.ground)
{
ismoving = true;
ShowEffet (hitInfo.point);
}
}
if (Input.GetMouseButtonUp (0))
{
ismoving = false;
}
if (ismoving)
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hitInfo;
bool isCollder = Physics.Raycast (ray, out hitInfo);
if (isCollder && hitInfo.collider.tag == Tags.ground)
{
LOOKATtarg (hitInfo.point);
}
}
else
{
if (playerMove.isMoving)
{
LOOKATtarg (tragetpostion);
}
}
}
void ShowEffet(Vector3 hitpoint)
{
hitpoint = new Vector3 (hitpoint.x, hitpoint.y + 0.1f, hitpoint.z);
GameObject.Instantiate (effetprefab, hitpoint, Quaternion.identity);
}
void LOOKATtarg(Vector3 hitInfo)
{
tragetpostion = hitInfo;
tragetpostion = new Vector3 (tragetpostion.x, transform.position.y, tragetpostion.z);
this.transform.LookAt (tragetpostion);
}
}