HoverRace教程脚本中的错误

时间:2018-08-13 19:11:34

标签: c# unity3d

在HoverRace教程资产包中,脚本未附加到任何游戏对象。这样做时会出现错误:

  

无法添加脚本行为后处理层。脚本需要   源自MonoBehavior。

以下是脚本之一:

//This script handles reading inputs from the player and passing it on to the vehicle. We 
//separate the input code from the behaviour code so that we can easily swap controls 
//schemes or even implement and AI "controller". Works together with the VehicleMovement script

using UnityEngine;

public class PlayerInput : MonoBehaviour
{
    public string verticalAxisName = "Vertical";        //The name of the thruster axis
    public string horizontalAxisName = "Horizontal";    //The name of the rudder axis
    public string brakingKey = "Brake";                 //The name of the brake button

    //We hide these in the inspector because we want 
    //them public but we don't want people trying to change them
    [HideInInspector] public float thruster;            //The current thruster value
    [HideInInspector] public float rudder;              //The current rudder value
    [HideInInspector] public bool isBraking;            //The current brake value

    void Update()
    {
        //If the player presses the Escape key and this is a build (not the editor), exit the game
        if (Input.GetButtonDown("Cancel") && !Application.isEditor)
            Application.Quit();

        //If a GameManager exists and the game is not active...
        if (GameManager.instance != null && !GameManager.instance.IsActiveGame())
        {
            //...set all inputs to neutral values and exit this method
            thruster = rudder = 0f;
            isBraking = false;
            return;
        }

        //Get the values of the thruster, rudder, and brake from the input class
        thruster = Input.GetAxis(verticalAxisName);
        rudder = Input.GetAxis(horizontalAxisName);
        isBraking = Input.GetButton(brakingKey);
    }
}

1 个答案:

答案 0 :(得分:0)

这一次发生在我身上。 确保此行中的“ PlayerInput” public class PlayerInput : MonoBehaviour是文件名。 它们必须相同。 您可以更改文件名或代码行。