![](/img/trans.png)
[英]There is no 'Rigidbody2D' attached to the "Player" game object, but a script is trying to access it. (Unity)
[英]MissingComponentException there is no rigidbody2D attached to gameObject but a script is trying to access it
我收到此錯誤。 我不知道為什么。
這是一個屏幕截圖:
http://www.siz.co.il/my.php?i=gmfmczmo3gzl.png
和我的腳本代碼:
using UnityEngine;
using System.Collections;
public class PlayerMovementV2 : MonoBehaviour
{
public KeyCode moveUp;
public KeyCode moveDown;
public KeyCode moveRight;
public KeyCode moveLeft;
public float playerVelocity = 1;
public Rigidbody2D rigid2D;
public Vector2 vector2;
// Use this for initialization
void Start()
{
rigid2D = GetComponent<Rigidbody2D>();
vector2 = new Vector2(rigid2D.velocity.x, playerVelocity);
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(moveUp))
{
rigid2D.velocity = vector2;
}
else
if (Input.GetKey(moveDown))
{
rigid2D.velocity = new Vector2(rigid2D.velocity.x,playerVelocity);
}
}
}
有什么建議么?
據我從圖片中看到的,gmae對象上附加了一個腳本,那么Unity3D向我要什么?
PS:它是最新的Unity3D版本。 昨天下載了。
關閉統一3D並將其重新插入后,問題得以解決。
謝謝你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.