画面をなぞった線の部分をオブジェクト化したいです。イメージ的には"Q universe"のようなかんじです。
GameObject gObj = null; Ray GenerateMouseRay(Vector3 touchPos){ Vector3 mousePosFar = new Vector3 (touchPos.x, touchPos.y, Camera.main.farClipPlane); Vector3 mousePosNear = new Vector3 (touchPos.x, touchPos.y, Camera.main.nearClipPlane); Vector3 mousePosF = Camera.main.ScreenToWorldPoint (mousePosFar); Vector3 mousePosN = Camera.main.ScreenToWorldPoint (mousePosNear); Ray mr = new Ray (mousePosN, mousePosF - mousePosN); return mr; } void Update () { float rayDistance; if(((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) || Input.GetMouseButton(0))){ Plane objPlane = new Plane(Camera.main.transform.forward * -1, this.transform.position); Ray mRay = Camera.main.ScreenPointToRay(Input.mousePosition); if(objPlane.Raycast(mRay, out rayDistance)){ this.transform.position = mRay.GetPoint(rayDistance); } Ray mouseRay = GenerateMouseRay (Input.mousePosition); RaycastHit hit; if(Physics.Raycast(mouseRay.origin, mouseRay.direction, out hit)){ gObj = hit.transform.gameObject; } } } コード
このようにしてみましたが線は引けるのですがオブジェクト化できません。
どのようにすればいいですか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/09 14:48
2017/07/09 22:40