RaycastHit hit;
Vector2 mousePosBegan = Input.mousePosition;
Ray ray = Camera.main.ScreenPointToRay(mousePosBegan);
//Is on the legal area:
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.tag.Equals("Enemy"))
{
}
}
if (Input.GetMouseButtonDown (0)) { Vector3 v = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hitInfo = Physics2D.Raycast(new Vector2(v.x, v.y), new Vector2(v.x, v.y),0.1f);//射线碰撞 if (Physics2D.Raycast(new Vector2(v.x, v.y), new Vector2(v.x, v.y), 0.1f)) { //Destroy(redpoint);//销毁上一个点 Debug.DrawLine(new Vector2(v.x, v.y), hitInfo.point);//绘制射线 gameObj = hitInfo.collider.gameObject;