[英]MissingComponentException there is no rigidbody2D attached to gameObject but a script is trying to access it
Im getting this error. 我收到此错误。 I have no idea why. 我不知道为什么。
Heres a screen shot: 这是一个屏幕截图:
http://www.siz.co.il/my.php?i=gmfmczmo3gzl.png http://www.siz.co.il/my.php?i=gmfmczmo3gzl.png
And my script code: 和我的脚本代码:
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);
}
}
}
Any suggestions? 有什么建议么?
As far as i seen from the picture there is a script attached to the gmae object so what does Unity3D wants from me? 据我从图片中看到的,gmae对象上附加了一个脚本,那么Unity3D向我要什么?
PS: Its the latest Unity3D version. PS:它是最新的Unity3D版本。 Downloaded it yesterday. 昨天下载了。
After I closed the unity 3D and reoppend it the problem was solved. 关闭统一3D并将其重新插入后,问题得以解决。
Thank you Evil Tak. 谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.