错误“无法添加脚本行为AssemblyInfo。该脚本需要从MonoBehaviour派生!”将脚本放入对象时

时间:2019-12-29 06:52:13

标签: c# unity3d

所以下面有一个代码,可以通过按键盘上的向左,向右,向上和向下键将对象向左,向右,向上和向下移动:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
Rigidbody rb;
public float speed = 2.0f;
void Start()
{
    rb = GetComponent<Rigidbody>();
    rb.freezeRotation = true;
}

void Update() 
{
    if (Input.GetKey(KeyCode.RightArrow))
        {
        rb.velocity = transform.right * speed;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
        rb.velocity = -transform.right * speed;
        }
        if (Input.GetKey(KeyCode.UpArrow))
        {
        rb.velocity = new Vector3(0, 0, 1) * speed;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
        rb.velocity = new Vector3(0, 0, -1) * speed;
        }
    }
}

但是每次我尝试将脚本导入到想要的对象时,它将始终显示错误:  无法添加脚本行为AssemblyInfo。  该脚本需要从MonoBehaviour派生! 我正在寻找从Unity网站到其他网站的所有答案,检查所有内容,但脚本没有错。 那怎么了?

0 个答案:

没有答案