[英]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.