ヘディングのテキスト### 前提・実現したいこと
Plane(Colider付き)の床の上で、マウスに追従する動きで指定されたオブジェクトを動かし、マウスの左クリックで固定を目指しています。マウスの追従に関してはMain CameraにアタッチされているRay(光線)によって追従は成功しており、Plane上に動いています。しかし、マウスをクリックして固定させる方法が上手に行きません。Rayに関するScriptを無効にしたり、Rigidbodyでx,y,zを固定にしても失敗しました。どなたかご教授お願いします。
(Script無効に関するものは、ボタンを押して特定のオブジェクトを生成するのですが、2つ以上のオブジェクトも動かなくなるので失敗しました)
ソースコード ```using System.Collections; using System.Collections.Generic; using UnityEngine; public class ray2 : MonoBehaviour { //public GameObject targetObject; Vector3 m_ZAixs; public Rigidbody m_Rigidbody; public GameObject Light; // Use this for initialization void Start() { m_Rigidbody = Light.GetComponent<Rigidbody>(); m_Rigidbody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionZ; // Update is called once per frame } void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { GameObject t = GameObject.Find("SpotLightWhite 1 1(Clone)"); var targetPos = new Vector3(hit.point.x, hit.point.y, hit.point.z); t.transform.position = targetPos; } } if (Input.GetKeyDown(KeyCode.S)) { //Light.GetComponent<Rigidbody>(); //m_Rigidbody.constraints = RigidbodyConstraints.FreezeAll; } } } ### 試したこと オブジェクトにRigidbodyを付与して、Frezzeしても動きます。 Rayで動かすScriptを無効化してもダメでした。 オブジェクトのTagを、マウスクリックした段階で変え、親ペアレントをカメラからPlaneに変えても失敗しました。 ### 補足情報(FW/ツールのバージョンなど) Unity Ver2017,3です
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。