KITASENJU DESIGN BLOG

memo, html, javascript, unity

ScreenToWorldPoint使い方

zが0だと動かないんで、適当に数字を入れておくのがポイント

Vector3 screen_point = Vector3.zero;

        #if UNITY_EDITOR

            screen_point = Input.mousePosition;

        #else
        
            if(Input.touchCount >= 1){

                Touch touch = Input.GetTouch(0);
                screen_point = new Vector3(
                    touch.position.x,
                    touch.position.y,
                    0
                );

            }

        #endif

        screen_point.z = scrZ;//0だと動かない!カメラかの距離

        var worldpos = _camera.ScreenToWorldPoint(screen_point);   
"FOOTER"