MissingComponentException: There is no 'Rigidbody2D' attached to the "Cube" game object, but a script is trying to access it.
You probably need to add a Rigidbody2D to the game object "Cube". Or your script needs to check if the component is attached before using it.
UnityEngine.Rigidbody2D.get_position () (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/modules/Physics2D/Physics2DBindings.gen.cs:1345)
Player2D.FixedUpdate () (at Assets/Player2D.cs:18)
とエラーが出ました。
CubeのインスペクタにRigidbody2Dをつけても、エラーが消えません。
CubeについているスクリプトはPlayer2D.csで
using UnityEngine; using System.Collections; public class Player2D : MonoBehaviour { Rigidbody2D rigidbody; Vector2 velocity; void Start () { rigidbody = GetComponent<Rigidbody2D> (); } void Update () { velocity = new Vector3 (Input.GetAxisRaw ("Horizontal"), Input.GetAxisRaw ("Vertical")).normalized * 10; } void FixedUpdate() { rigidbody.MovePosition (rigidbody.position + velocity * Time.fixedDeltaTime); } }
と書きました。
どこを直せば良いのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。