前提・実現したいこと
向きを取得して向きに応じたエネルギーを与える
発生している問題・エラーメッセージ
再生しても All compiler errors have to be fixed before you can enter play mode と出て実行できません。 恐らくTransform.Rotate.yを取得できていない と思うのですが.文法などの間違いがあったら教えてください。
該当のソースコード
c#
1using UnityEngine; 2using System.Collections; 3 4public class 移動P : MonoBehaviour 5{ 6 public float zspeed = 10; 7 // Start is called before the first frame update 8 void Start() 9 { 10 11 12 13 } 14 15 // Update is called once per frame 16 void Update() 17 { 18 Transform my2Transform = this.transform; 19 if (Input.GetKey("left")) { my2Transform.Rotate(0f, -1f, 0f); } 20 if (Input.GetKey("right")) { my2Transform.Rotate(0f, 1f, 0f); } 21 float kz = 0; 22 float x = 0; 23 float z = Input.GetAxis("Vertical"); 24 if ( x == 234) { 25 x = 0; 26 } 27 if (my2Transform.Rotate.y < 90 && my2Transform.Rotate.y > 0) 28 { x = 1; 29 kz = -90 / my2Transform.Rotate.y - 90; 30 x = z - kz; 31 z = z - kz; 32 } 33 Rigidbody rigidbody = GetComponent<Rigidbody>(); 34 35 rigidbody.AddForce(x * zspeed, 0, z * zspeed); 36 } 37}
###恐らく問題の部分(無くしたら動いた)
C#
1 if (my2Transform.Rotate.y < 90 && my2Transform.Rotate.y > 0) 2 { x = 1; 3 kz = -90 / my2Transform.Rotate.y - 90; 4 x = z - kz; 5 z = z - kz; 6 } 7
試したこと
Transformの代入はエラーを出しませんでしたが.
Transform.Rotate.yを変数に代入使用としていた時は
エラーを出したので.Rotate.yに問題があると思います。
補足情報(FW/ツールのバージョンなど)
Unty 2018.3.3f1 Personal
Visual Studio 2017
.NET Framework 4.6.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/02/17 19:57
2019/02/17 20:00