質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

1回答

4351閲覧

The name `playerTransform' does not exist in the current contextのエラー

退会済みユーザー

退会済みユーザー

総合スコア0

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2016/10/11 07:08

Assets/Script/EvasiveManeuver.cs(21,17): error CS0103: The name `playerTransform' does not exist in the current context
とエラーが出ます。

using UnityEngine; using System.Collections; public class EvasiveManeuver : MonoBehaviour { public float dodge; public float smoothing; public float tilt; public Vector2 startWait; public Vector2 maneuverTime; public Vector2 maneuverWait; public Boundary boundary; private float currentSpeed; private float targetManeuver; private Rigidbody rb; // Use this for initialization void Start () { rb = GetComponent <Rigidbody> (); playerTransform = GameObject.FindGameObjectWithTag ("Player").transform; currentSpeed = rb.velocity.z; StartCoroutine (Evade ()); } IEnumerator Evade() { yield return new WaitForSeconds (Random.Range (startWait.x, startWait.y)); while (true) { targetManeuver = Random.Range (1, dodge) * -Mathf.Sign (transform.position.x); yield return new WaitForSeconds (Random.Range (maneuverTime.x, maneuverTime.y)); targetManeuver = 0; yield return new WaitForSeconds (Random.Range (maneuverWait.x, maneuverWait.y)); } } void FixedUpdate () { float newManeuver = Mathf.MoveTowards (rb.velocity.x, targetManeuver, Time.deltaTime * smoothing); rb.velocity = new Vector3 (newManeuver, 0.0f, currentSpeed); rb.position = new Vector3( Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax) ); rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt); } }

とコードを書いたのですが

playerTransform = GameObject.FindGameObjectWithTag ("Player").transform;

の部分のどこが間違っているのでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

EvasiveManeuverクラスにplayerTransformというメンバ変数(フィールド)が見当たりません。
その名前のメンバ変数はMonoBehaviourに元々あるものではないので自分で宣言する必要があります。

投稿2016/10/11 08:05

ishi9

総合スコア1294

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問