Unity物体跟随鼠标移动

public void Tool_Move_Follow_Mouse(GameObject Tool_GameObject)
{
    float distanceFromCamera = 1f; // 根据需要调整此值
    //修正鼠标点的坐标
    Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distanceFromCamera);
    //将修正后的鼠标点 转换成世界坐标
    Vector3 mouseSToW = Camera.main.ScreenToWorldPoint(mousePos);
    Tool_GameObject.transform.position = mouseSToW + new Vector3(0f, 0f, 0f);
    //Tool_GameObject.transform.LookAt(Camera.main.transform.position);
    Tool_GameObject.transform.localEulerAngles = new Vector3(0,135,0);
}

猜你喜欢

转载自blog.csdn.net/cherry_f_f/article/details/140503963