Assets/Script/PlayerController.cs(21,27): warning CS0414: The private field `PlayerController.rb' is assigned but its value is never used
とエラーが出ました。
using UnityEngine; using System.Collections; [System.Serializable] public class Boundary { public float xMin,xMax,zMin,zMax; } public class PlayerController : MonoBehaviour { public float speed; public float tilt; public Boundary boundary; // int,long public GameObject shot; public Transform[] shotSpawn; public float fireRate; private float nextFire; private Rigidbody rb; private AudioSource audioSource; void Start() { rb = GetComponent <Rigidbody> (); audioSource = GetComponent<AudioSource> (); } void Update() { if (Input.GetButton("Fire1") && Time.time > nextFire) { nextFire = Time.time + fireRate; GameObject clone = Instantiate(shot, transform.position, transform.rotation) as GameObject; GetComponent<AudioSource>().Play (); } } void FixedUpdate (){ float movehorizontal = Input.GetAxis ("Horizontal"); // ローカル変数 float movevertical= Input.GetAxis ("Vertical"); Vector3 movement = new Vector3 (movehorizontal, 0.0f, movevertical); Rigidbody rigidbody = GetComponent<Rigidbody> (); rigidbody.velocity = movement * speed; rigidbody.position = new Vector3(Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax) ); rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt); } }
の
private Rigidbody rb;
の部分を指摘されたのですが、
rb = GetComponent <Rigidbody> ();
の部分でrbは使われているのでどうしてこのようにエラーが出るのかわかりません。
どのように改善したら良いのでしょうか?

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。