KITASENJU DESIGN BLOG

memo, html, javascript, unity

rayを使わずマウス位置を取得

 
Vector3 getMousePos(){

        var p = Input.mousePosition;
        _mousePos.x = 2f*(p.x / (float)Screen.width - 0.5f);
        _mousePos.y = 2f*(p.y / (float)Screen.height -0.5f);

        float screenH = (float)_camera.orthographicSize;//OrthographicCameraにおける高さ
        float screenW = (float)_camera.orthographicSize*Screen.width/Screen.height;//幅

        var tgt = new Vector3(
            screenW*_mousePos.x,
            screenH*_mousePos.y,
            _mouseZ
        );
        return tgt;

}

"FOOTER"