前提・実現したいこと
Unityでエレベータを作成したいと思っています。
今参考にさせてもらっているのは、Youtubeの方で紹介されている動画を参考に作成しています。
そこで、Standard AssetのDrag RightBody(Script)を使用するのですが、その動画ではDrag RightBodyの設定欄にカメラを指定する設定や、GradButtonの設定などする場所があります。
その動画で配布されているzipファイルにはその設定が入っている、Drag RightBodyにはその設定する場所がありません。
その設定なしだと、ボタンを押したら動くはずなのですが、ボタンを押しても動きませんでした。
そこで、カメラを追加するScriptは書けた(正解かは分かりません)のですが、他の設定の追加方法が分かりません。
追加したのは
[SerializeField] private Camera PlayerCam;
参考になりそうなサイトなどあれば教えてもらえないでしょうか?
該当のソースコード
C#
1using System; 2using System.Collections; 3using UnityEngine; 4 5namespace UnityStandardAssets.Utility 6{ 7 public class DragRigidbody : MonoBehaviour 8 { 9 [SerializeField] private Camera PlayerCam; 10 const float k_Spring = 50.0f; 11 const float k_Damper = 5.0f; 12 const float k_Drag = 10.0f; 13 const float k_AngularDrag = 5.0f; 14 const float k_Distance = 0.2f; 15 const bool k_AttachToCenterOfMass = false; 16 17 private SpringJoint m_SpringJoint; 18 19 20 private void Update() 21 { 22 // Make sure the user pressed the mouse down 23 if (!Input.GetMouseButtonDown(0)) 24 { 25 return; 26 } 27 28 var mainCamera = FindCamera(); 29 30 // We need to actually hit an object 31 RaycastHit hit = new RaycastHit(); 32 if ( 33 !Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition).origin, 34 mainCamera.ScreenPointToRay(Input.mousePosition).direction, out hit, 100, 35 Physics.DefaultRaycastLayers)) 36 { 37 return; 38 } 39 // We need to hit a rigidbody that is not kinematic 40 if (!hit.rigidbody || hit.rigidbody.isKinematic) 41 { 42 return; 43 } 44 45 if (!m_SpringJoint) 46 { 47 var go = new GameObject("Rigidbody dragger"); 48 Rigidbody body = go.AddComponent<Rigidbody>(); 49 m_SpringJoint = go.AddComponent<SpringJoint>(); 50 body.isKinematic = true; 51 } 52 53 m_SpringJoint.transform.position = hit.point; 54 m_SpringJoint.anchor = Vector3.zero; 55 56 m_SpringJoint.spring = k_Spring; 57 m_SpringJoint.damper = k_Damper; 58 m_SpringJoint.maxDistance = k_Distance; 59 m_SpringJoint.connectedBody = hit.rigidbody; 60 61 StartCoroutine("DragObject", hit.distance); 62 } 63 64 65 private IEnumerator DragObject(float distance) 66 { 67 var oldDrag = m_SpringJoint.connectedBody.drag; 68 var oldAngularDrag = m_SpringJoint.connectedBody.angularDrag; 69 m_SpringJoint.connectedBody.drag = k_Drag; 70 m_SpringJoint.connectedBody.angularDrag = k_AngularDrag; 71 var mainCamera = FindCamera(); 72 while (Input.GetMouseButton(0)) 73 { 74 var ray = mainCamera.ScreenPointToRay(Input.mousePosition); 75 m_SpringJoint.transform.position = ray.GetPoint(distance); 76 yield return null; 77 } 78 if (m_SpringJoint.connectedBody) 79 { 80 m_SpringJoint.connectedBody.drag = oldDrag; 81 m_SpringJoint.connectedBody.angularDrag = oldAngularDrag; 82 m_SpringJoint.connectedBody = null; 83 } 84 } 85 86 87 private Camera FindCamera() 88 { 89 if (GetComponent<Camera>()) 90 { 91 return GetComponent<Camera>(); 92 } 93 94 return Camera.main; 95 } 96 } 97} 98
試したこと
他のサイトなどを見てその設定があるDrag RightBodyを探しましたが見当たりませんでした。
補足情報(FW/ツールのバージョンなど)
Unity 2017.2.17fを使用しています。
参考にしているサイトは以下の動画です。
リンク内容
回答1件
あなたの回答
tips
プレビュー