在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);
}
}发布于 2018-08-13 19:15:27
这事曾经发生在我身上。确保此行中的"PlayerInput“public class PlayerInput : MonoBehaviour是文件名。他们必须是一样的。您可以更改文件名或代码行。
https://stackoverflow.com/questions/51829076
复制相似问题