error: Type '[Assembly-UnityScript] extra field
error: Type '[Assembly-UnityScript] extra field
我这里有这个脚本,但出于某种原因我收到了这个错误。
Type '[Assembly-UnityScript]PlayerGUI' has an extra field
'healthFallRate' of type 'System.Int32' in the player and thus can't
be serialized (expected 'healthBarDisplay' of type 'System.Single')
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
#pragma strict
//Size of Textures
var size : Vector2 = new Vector2(240, 40);
var sizeXP1 : Vector2 = new Vector2(40, 20);
var sizeXP2 : Vector2 = new Vector2(100, 20);
//Health Variables
var healthPos : Vector2 = new Vector2(20, 20);
var healthFallRate : int = 150;
var healthBarDisplay : float = 1;
var healthBarEmpty : Texture2D;
var healthBarFull : Texture2D;
//Hunger Variables
var hungerPos : Vector2 = new Vector2(20, 60);
var hungerFallRate : int = 150;
var hungerBarDisplay : float = 1;
var hungerBarEmpty : Texture2D;
var hungerBarFull : Texture2D;
//Thirst Variables
var thirstPos : Vector2 = new Vector2(20, 100);
var thirstFallRate : int = 100;
var thirstBarDisplay : float = 1;
var thirstBarEmpty : Texture2D;
var thirstBarFull : Texture2D;
//Stamina Variables
var staminaPos : Vector2 = new Vector2(20, 140);
var staminaFallRate : int = 35;
var staminaBarDisplay : float = 1;
var staminaBarEmpty : Texture2D;
var staminaBarFull : Texture2D;
//Level Up System
var currentXPPos : Vector2 = new Vector2(20, 180);
var currentXP : int = 0;
var maxXP : int = 50;
var level : int = 1;
private var leveledUp : boolean = true;
var timeToShowLevelUp : float = 3f;
var timeTillNotShowLevelUp : float = 0f;
private var chMotor : CharacterMotor;
private var controller : CharacterController;
var canJump : boolean = false;
var jumpTimer : float = 0.7;
var beginningSound : AudioClip;
private var deathMenu : DeathMenu;
function Start () {
chMotor = GetComponent(CharacterMotor);
controller = GetComponent(CharacterController);
deathMenu = GameObject.Find("First Person Controller").GetComponent(DeathMenu);
yield WaitForSeconds (5);
audio.PlayOneShot(beginningSound);
}
function OnGUI () {
//Health GUI
GUI.BeginGroup(new Rect (healthPos.x, healthPos.y, size.x, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), healthBarEmpty);
GUI.BeginGroup(new Rect (0, 0, size.x * healthBarDisplay, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), healthBarFull);
GUI.EndGroup();
GUI.EndGroup();
//Hunger GUI
GUI.BeginGroup(new Rect (hungerPos.x, hungerPos.y, size.x, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), hungerBarEmpty);
GUI.BeginGroup(new Rect (0, 0, size.x * hungerBarDisplay, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), hungerBarFull);
GUI.EndGroup();
GUI.EndGroup();
//Thirst GUI
GUI.BeginGroup(new Rect (thirstPos.x, thirstPos.y, size.x, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), thirstBarEmpty);
GUI.BeginGroup(new Rect (0, 0, size.x * thirstBarDisplay, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), thirstBarFull);
GUI.EndGroup();
GUI.EndGroup();
//Stamina GUI
GUI.BeginGroup(new Rect (staminaPos.x, staminaPos.y, size.x, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), staminaBarEmpty);
GUI.BeginGroup(new Rect (0, 0, size.x * staminaBarDisplay, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), staminaBarFull);
GUI.EndGroup();
GUI.EndGroup();
GUI.BeginGroup(new Rect (currentXPPos.x, currentXPPos.y, size.x, size.y));
GUI.Box(new Rect(0, 20, sizeXP1.x, sizeXP1.y), "XP");
GUI.Box(new Rect(0, 0, sizeXP1.x, sizeXP1.y), "Level");
GUI.Box(new Rect(40, 20, sizeXP2.x, sizeXP2.y), currentXP + "/" + maxXP);
GUI.Box(new Rect(40, 0, sizeXP2.x, sizeXP2.y), level + "");
GUI.EndGroup();
//currentXPPos
}
function Update() {
//Health Control
if(hungerBarDisplay <= 0 && (thirstBarDisplay <= 0)) {
healthBarDisplay -= Time.deltaTime / healthFallRate * 2;
}
else {
if(hungerBarDisplay <= 0 || thirstBarDisplay <= 0) {
healthBarDisplay -= Time.deltaTime / healthFallRate;
}
}
if(healthBarDisplay <= 0) {
deathMenu.enabled = true;
Debug.Log("deathMenu.enabled");
}
//Hunger Control
if(hungerBarDisplay >= 0) {
hungerBarDisplay -= Time.deltaTime / hungerFallRate;
}
if(hungerBarDisplay <= 0) {
hungerBarDisplay = 0;
}
if(hungerBarDisplay >= 1) {
hungerBarDisplay = 1;
}
//Thirst Control
if(thirstBarDisplay >= 0) {
thirstBarDisplay -= Time.deltaTime / thirstFallRate;
}
if(thirstBarDisplay <= 0) {
thirstBarDisplay = 0;
}
if(thirstBarDisplay >= 1) {
thirstBarDisplay = 1;
}
//Stamina Control
if(controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift)) {
chMotor.movement.maxForwardSpeed = 10;
chMotor.movement.maxSidewaysSpeed = 10;
staminaBarDisplay -= Time.deltaTime / staminaFallRate;
}
else {
chMotor.movement.maxForwardSpeed = 6;
chMotor.movement.maxSidewaysSpeed = 6;
staminaBarDisplay += Time.deltaTime / staminaFallRate;
}
//Jumping Section
if(Input.GetKeyDown(KeyCode.Space) && canJump == true) {
staminaBarDisplay -= 0.2;
Wait();
}
if(canJump == false) {
jumpTimer -= Time.deltaTime;
chMotor.jumping.enabled = false;
}
if(jumpTimer <= 0) {
canJump = true;
chMotor.jumping.enabled = true;
jumpTimer = 0.7;
}
if(staminaBarDisplay >= 1) {
staminaBarDisplay = 1;
}
if(staminaBarDisplay <= 0) {
staminaBarDisplay = 0;
canJump = false;
chMotor.jumping.enabled = false;
chMotor.movement.maxForwardSpeed = 6;
chMotor.movement.maxSidewaysSpeed = 6;
}
if(staminaBarDisplay < 0.2) {
canJump = false;
chMotor.jumping.enabled = false;
}
if(currentXP >= maxXP) {
LevelUpSystem();
}
if(leveledUp) {
if(Time.time > timeTillNotShowLevelUp) {
leveledUp = false;
}
}
}
function Wait() {
yield WaitForSeconds(0.1);
canJump = false;
}
function LevelUpSystem() {
currentXP = 0;
maxXP = maxXP + 50;
level++;
leveledUp = true;
timeTillNotShowLevelUp = Time.time + timeToShowLevelUp;
healthBarDisplay += 1;
hungerBarDisplay += 1;
thirstBarDisplay += 1;
staminaBarDisplay += 1;
}
相同 problem.I 认为您是通过命令行构建的 options.And 您在构建之前没有设置 Buildtarget,解决方案是设置 target.like:
/Applications/Unity5_2/Unity.app/Contents/MacOS/Unity -batchmode -quit -executeMethod YOUR_BUILD_METHOD -projectPath YOUR_ROJECT_PATH -buildTarget ios
然后你解决了这个问题。
我这里有这个脚本,但出于某种原因我收到了这个错误。
Type '[Assembly-UnityScript]PlayerGUI' has an extra field 'healthFallRate' of type 'System.Int32' in the player and thus can't be serialized (expected 'healthBarDisplay' of type 'System.Single') UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
#pragma strict
//Size of Textures
var size : Vector2 = new Vector2(240, 40);
var sizeXP1 : Vector2 = new Vector2(40, 20);
var sizeXP2 : Vector2 = new Vector2(100, 20);
//Health Variables
var healthPos : Vector2 = new Vector2(20, 20);
var healthFallRate : int = 150;
var healthBarDisplay : float = 1;
var healthBarEmpty : Texture2D;
var healthBarFull : Texture2D;
//Hunger Variables
var hungerPos : Vector2 = new Vector2(20, 60);
var hungerFallRate : int = 150;
var hungerBarDisplay : float = 1;
var hungerBarEmpty : Texture2D;
var hungerBarFull : Texture2D;
//Thirst Variables
var thirstPos : Vector2 = new Vector2(20, 100);
var thirstFallRate : int = 100;
var thirstBarDisplay : float = 1;
var thirstBarEmpty : Texture2D;
var thirstBarFull : Texture2D;
//Stamina Variables
var staminaPos : Vector2 = new Vector2(20, 140);
var staminaFallRate : int = 35;
var staminaBarDisplay : float = 1;
var staminaBarEmpty : Texture2D;
var staminaBarFull : Texture2D;
//Level Up System
var currentXPPos : Vector2 = new Vector2(20, 180);
var currentXP : int = 0;
var maxXP : int = 50;
var level : int = 1;
private var leveledUp : boolean = true;
var timeToShowLevelUp : float = 3f;
var timeTillNotShowLevelUp : float = 0f;
private var chMotor : CharacterMotor;
private var controller : CharacterController;
var canJump : boolean = false;
var jumpTimer : float = 0.7;
var beginningSound : AudioClip;
private var deathMenu : DeathMenu;
function Start () {
chMotor = GetComponent(CharacterMotor);
controller = GetComponent(CharacterController);
deathMenu = GameObject.Find("First Person Controller").GetComponent(DeathMenu);
yield WaitForSeconds (5);
audio.PlayOneShot(beginningSound);
}
function OnGUI () {
//Health GUI
GUI.BeginGroup(new Rect (healthPos.x, healthPos.y, size.x, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), healthBarEmpty);
GUI.BeginGroup(new Rect (0, 0, size.x * healthBarDisplay, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), healthBarFull);
GUI.EndGroup();
GUI.EndGroup();
//Hunger GUI
GUI.BeginGroup(new Rect (hungerPos.x, hungerPos.y, size.x, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), hungerBarEmpty);
GUI.BeginGroup(new Rect (0, 0, size.x * hungerBarDisplay, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), hungerBarFull);
GUI.EndGroup();
GUI.EndGroup();
//Thirst GUI
GUI.BeginGroup(new Rect (thirstPos.x, thirstPos.y, size.x, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), thirstBarEmpty);
GUI.BeginGroup(new Rect (0, 0, size.x * thirstBarDisplay, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), thirstBarFull);
GUI.EndGroup();
GUI.EndGroup();
//Stamina GUI
GUI.BeginGroup(new Rect (staminaPos.x, staminaPos.y, size.x, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), staminaBarEmpty);
GUI.BeginGroup(new Rect (0, 0, size.x * staminaBarDisplay, size.y));
GUI.Box(Rect(0, 0, size.x, size.y), staminaBarFull);
GUI.EndGroup();
GUI.EndGroup();
GUI.BeginGroup(new Rect (currentXPPos.x, currentXPPos.y, size.x, size.y));
GUI.Box(new Rect(0, 20, sizeXP1.x, sizeXP1.y), "XP");
GUI.Box(new Rect(0, 0, sizeXP1.x, sizeXP1.y), "Level");
GUI.Box(new Rect(40, 20, sizeXP2.x, sizeXP2.y), currentXP + "/" + maxXP);
GUI.Box(new Rect(40, 0, sizeXP2.x, sizeXP2.y), level + "");
GUI.EndGroup();
//currentXPPos
}
function Update() {
//Health Control
if(hungerBarDisplay <= 0 && (thirstBarDisplay <= 0)) {
healthBarDisplay -= Time.deltaTime / healthFallRate * 2;
}
else {
if(hungerBarDisplay <= 0 || thirstBarDisplay <= 0) {
healthBarDisplay -= Time.deltaTime / healthFallRate;
}
}
if(healthBarDisplay <= 0) {
deathMenu.enabled = true;
Debug.Log("deathMenu.enabled");
}
//Hunger Control
if(hungerBarDisplay >= 0) {
hungerBarDisplay -= Time.deltaTime / hungerFallRate;
}
if(hungerBarDisplay <= 0) {
hungerBarDisplay = 0;
}
if(hungerBarDisplay >= 1) {
hungerBarDisplay = 1;
}
//Thirst Control
if(thirstBarDisplay >= 0) {
thirstBarDisplay -= Time.deltaTime / thirstFallRate;
}
if(thirstBarDisplay <= 0) {
thirstBarDisplay = 0;
}
if(thirstBarDisplay >= 1) {
thirstBarDisplay = 1;
}
//Stamina Control
if(controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift)) {
chMotor.movement.maxForwardSpeed = 10;
chMotor.movement.maxSidewaysSpeed = 10;
staminaBarDisplay -= Time.deltaTime / staminaFallRate;
}
else {
chMotor.movement.maxForwardSpeed = 6;
chMotor.movement.maxSidewaysSpeed = 6;
staminaBarDisplay += Time.deltaTime / staminaFallRate;
}
//Jumping Section
if(Input.GetKeyDown(KeyCode.Space) && canJump == true) {
staminaBarDisplay -= 0.2;
Wait();
}
if(canJump == false) {
jumpTimer -= Time.deltaTime;
chMotor.jumping.enabled = false;
}
if(jumpTimer <= 0) {
canJump = true;
chMotor.jumping.enabled = true;
jumpTimer = 0.7;
}
if(staminaBarDisplay >= 1) {
staminaBarDisplay = 1;
}
if(staminaBarDisplay <= 0) {
staminaBarDisplay = 0;
canJump = false;
chMotor.jumping.enabled = false;
chMotor.movement.maxForwardSpeed = 6;
chMotor.movement.maxSidewaysSpeed = 6;
}
if(staminaBarDisplay < 0.2) {
canJump = false;
chMotor.jumping.enabled = false;
}
if(currentXP >= maxXP) {
LevelUpSystem();
}
if(leveledUp) {
if(Time.time > timeTillNotShowLevelUp) {
leveledUp = false;
}
}
}
function Wait() {
yield WaitForSeconds(0.1);
canJump = false;
}
function LevelUpSystem() {
currentXP = 0;
maxXP = maxXP + 50;
level++;
leveledUp = true;
timeTillNotShowLevelUp = Time.time + timeToShowLevelUp;
healthBarDisplay += 1;
hungerBarDisplay += 1;
thirstBarDisplay += 1;
staminaBarDisplay += 1;
}
相同 problem.I 认为您是通过命令行构建的 options.And 您在构建之前没有设置 Buildtarget,解决方案是设置 target.like:
/Applications/Unity5_2/Unity.app/Contents/MacOS/Unity -batchmode -quit -executeMethod YOUR_BUILD_METHOD -projectPath YOUR_ROJECT_PATH -buildTarget ios
然后你解决了这个问题。