我是Unity的新手
following a tutorial
,但当我编写代码时,我会收到以下错误:
无法隐式转换类型“UnityEngine”。Rigidbody2D到UnityEngine。刚性体'
代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCtrl : MonoBehaviour
{
public float movSpeed;
float speedX, speedY;
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
speedX = Input.GetAxisRaw("Horizontal") * movSpeed;
speedY = Input.GetAxisRaw("Vertical") * movSpeed;
rb.velocity = new Vector2(speedX, speedY);
}
}
我该怎么解决这个问题?
我尝试调试和重写代码,但问题仍然存在。