前提・実現したいこと
Unityで2Dシューティング風ゲームを作っていたのですが、自機の移動範囲の設定がうまくいきません。まだ素人のため、ブログなどを参考にプログラムを打ち込んでいます。
「自機を方向キーで上下左右に動かす」というプログラムに移動制限をつけようとしたところ、以下のエラーメッセージが発生しました。回答していただけると助かります・・・
発生している問題・エラーメッセージ
CS0103 The name '〇〇' does not exist in the current context
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class srydingScript : MonoBehaviour { 6 7 void Start () { 8 9 } 10 11 void Update () { 12 if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKey(KeyCode.LeftArrow)) { 13 transform.Translate (-0.1f, 0, 0); 14 } 15 16 if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKey(KeyCode.RightArrow)) { 17 transform.Translate (0.1f, 0, 0); 18 } 19 20 if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKey(KeyCode.UpArrow)) { 21 transform.Translate (0, 0.1f, 0); 22 } 23 24 if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKey(KeyCode.DownArrow)) { 25 transform.Translate (0, -0.1f, 0); 26 } 27 } 28}
試したこと
このプログラムの下部に「Mathf.Clamp~」というコードを入れようとしたところ、上記のエラーが発生しました。適用したいオブジェクトの名前は「sryding」です。
エラーコードの意味は分かったのですが、「宣言」をどうやったらいいのか分からず・・・
補足情報(FW/ツールのバージョンなど)
Unity 5.6.5f1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/03 14:14