C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class BallController : MonoBehaviour { 6 7 public Rigidbody rb; 8 9 10 // Update is called once per frame 11 void Update () { 12 if (Input.GetKey(KeyCode.W)){ 13 transform.GetComponent<Rigidbody>().AddForce(0,0,5); 14 } 15 if (Input.GetKey(KeyCode.S)){ 16 transform.GetComponent<Rigidbody>().AddForce(0,0,-5); 17 } 18 if (Input.GetKey(KeyCode.D)){ 19 transform.GetComponent<Rigidbody>().AddForce(5,0,0); 20 } 21 if (Input.GetKey (KeyCode.A)) { 22 transform.GetComponent<Rigidbody> ().AddForce (-5 , 0, 0); 23 } 24 if (Input.GetKey (KeyCode.F)) { 25 rb.isKinematic = true; 26 } 27} 28}
これで、Fキーを押せば、止まるかと思ったのですが、
UnassignedReferenceException: The variable rb of BallController has not been assigned.
You probably need to assign the rb variable of the BallController script in the inspector.
BallController.Update () (at Assets/MyScript/BallController.cs:25)
と、エラー文が出てきました。
解決法は、ないでしょうか。
回答お願いします!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。