0
我忙我自己的Unity3d遊戲的工作,這裏是其中一個腳本我目前有:Unity3d C#分配錯誤
HungerHandler.cs
using UnityEngine;
using System.Collections;
using ProgressBar;
public class HungerHandler : MonoBehaviour {
private ProgressBarBehaviour behaviour;
public bool Start() {
if (!this.behaviour = GameObject.Find("hungerBar").GetComponent<ProgressBarBehaviour>()) {
return false;
}
this.behaviour.Value = 0f;
return true;
}
public bool Add(int percentage){
if (this.behaviour.Value < 100) {
this.behaviour.Value = this.behaviour.Value + percentage;
return true;
}
return false;
}
public bool Damage(int percentage){
if ((this.behaviour.Value - percentage) > 0) {
this.behaviour.Value = this.behaviour.Value - percentage;
return true;
}
return false;
}
}
當我嘗試運行我的遊戲我得到一個錯誤:
Assets/custom/handlers/HungerHandler.cs(9,27): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
此錯誤是纏着我了,因爲我至今都與所有其他基本相同腳本沒有問題,所以我不知道w ^我在這裏做錯了什麼?我該如何解決這個錯誤?
親切的問候, 喬瓦尼·格蘭德
嘗試!(this.behaviour = ...) –
我試過這個,這沒有改變任何東西 –
你正在混合一個布爾測試的assignement。我想你想要的東西像_if((this.behaviour = find ....)== null)返回false; _ – Steve