前提
unityのほかのスクリプトの変数を取得したいのですが、うまくいきません。
https://obenkyolab.com/?p=2294
https://yttm-work.jp/unity/unity_0012.html
https://htsuda.net/archives/1702
これらのサイトを参考にして、以下のようなコードを作ってみました。
C#
1Debug.Log(Cinemachine.CinemachineDollyCart ,m_Speed);
これで、CinemachineDollyCart.csというファイル内のm_Speedという変数を取得できるだろうと思っていたのですが、できませんでした。
エラーメッセージ
error CS0119: 'CinemachineDollyCart' is a type, which is not valid in the given context error CS0103: The name 'm_Speed' does not exist in the current context
なお、CinemachineDollyCart.csのコードは以下のようになっています。
C#
1using UnityEngine; 2using UnityEngine.Serialization; 3 4namespace Cinemachine 5{ 6 /// <summary> 7 /// This is a very simple behaviour that constrains its transform to a CinemachinePath. 8 /// It can be used to animate any objects along a path, or as a Follow target for 9 /// Cinemachine Virtual Cameras. 10 /// </summary> 11 [DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)] 12 [ExecuteAlways] 13 [DisallowMultipleComponent] 14 [HelpURL(Documentation.BaseURL + "manual/CinemachineDollyCart.html")] 15 public class CinemachineDollyCart : MonoBehaviour 16 { 17 /// <summary>The path to follow</summary> 18 [Tooltip("The path to follow")] 19 public CinemachinePathBase m_Path; 20 21 /// <summary>This enum defines the options available for the update method.</summary> 22 public enum UpdateMethod 23 { 24 /// <summary>Updated in normal MonoBehaviour Update.</summary> 25 Update, 26 /// <summary>Updated in sync with the Physics module, in FixedUpdate</summary> 27 FixedUpdate, 28 /// <summary>Updated in normal MonoBehaviour LateUpdate</summary> 29 LateUpdate 30 }; 31 32 /// <summary>When to move the cart, if Velocity is non-zero</summary> 33 [Tooltip("When to move the cart, if Velocity is non-zero")] 34 public UpdateMethod m_UpdateMethod = UpdateMethod.Update; 35 36 /// <summary>How to interpret the Path Position</summary> 37 [Tooltip("How to interpret the Path Position. If set to Path Units, values are as follows: 0 represents the first waypoint on the path, 1 is the second, and so on. Values in-between are points on the path in between the waypoints. If set to Distance, then Path Position represents distance along the path.")] 38 public CinemachinePathBase.PositionUnits m_PositionUnits = CinemachinePathBase.PositionUnits.Distance; 39 40 /// <summary>Move the cart with this speed</summary> 41 [Tooltip("Move the cart with this speed along the path. The value is interpreted according to the Position Units setting.")] 42 [FormerlySerializedAs("m_Velocity")] 43 public float m_Speed; 44 45 /// <summary>The cart's current position on the path, in distance units</summary> 46 [Tooltip("The position along the path at which the cart will be placed. This can be animated directly or, if the velocity is non-zero, will be updated automatically. The value is interpreted according to the Position Units setting.")] 47 [FormerlySerializedAs("m_CurrentDistance")] 48 public float m_Position; 49 50 void FixedUpdate() 51 { 52 if (m_UpdateMethod == UpdateMethod.FixedUpdate) 53 SetCartPosition(m_Position + m_Speed * Time.deltaTime); 54 } 55 56 void Update() 57 { 58 float speed = Application.isPlaying ? m_Speed : 0; 59 if (m_UpdateMethod == UpdateMethod.Update) 60 SetCartPosition(m_Position + speed * Time.deltaTime); 61 } 62 63 void LateUpdate() 64 { 65 if (!Application.isPlaying) 66 SetCartPosition(m_Position); 67 else if (m_UpdateMethod == UpdateMethod.LateUpdate) 68 SetCartPosition(m_Position + m_Speed * Time.deltaTime); 69 } 70 71 void SetCartPosition(float distanceAlongPath) 72 { 73 if (m_Path != null) 74 { 75 m_Position = m_Path.StandardizeUnit(distanceAlongPath, m_PositionUnits); 76 transform.position = m_Path.EvaluatePositionAtUnit(m_Position, m_PositionUnits); 77 transform.rotation = m_Path.EvaluateOrientationAtUnit(m_Position, m_PositionUnits); 78 } 79 } 80 } 81} 82
試したこと
検索等をした
補足情報(FW/ツールのバージョンなど)
どうしたらよいのでしょうか。
質問に不備があればコメントで教えてください。
かれこれ3時間ほど悩んでいます。
どうかよろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー