首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HoverRace教程脚本中的错误

HoverRace教程脚本中的错误
EN

Stack Overflow用户
提问于 2018-08-13 19:11:33
回答 1查看 43关注 0票数 0

在HoverRace教程资产包中,脚本不附加到任何游戏对象。在这样做时,它会产生一个错误:

无法添加脚本行为后处理层。脚本需要从MonoBehavior派生。

下面是其中一个脚本:

代码语言:javascript
复制
//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);
    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-08-13 19:15:27

这事曾经发生在我身上。确保此行中的"PlayerInput“public class PlayerInput : MonoBehaviour是文件名。他们必须是一样的。您可以更改文件名或代码行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51829076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档