[英]Unity3d C# assignment error
我正在忙於自己的Unity3d游戲,這是我目前擁有的腳本之一:
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
因為到目前為止我對所有其他基本相同的腳本都沒有問題,所以這個錯誤使我煩惱,所以我想知道我在這里做錯了什么嗎? 我該如何解決此錯誤?
親切的問候,喬凡尼·勒格蘭德
正如@Steve指出的那樣,您正在將賦值調用與布爾測試混在一起。 可能這就是您想要做的。
this.behaviour = GameObject.Find("hungerBar").GetComponent<ProgressBarBehaviour>();
if (this.behaviour == null) {
return false;
}
但是這是另一回事。 由於您正在使用MonoBehaviour
s-最好通過Unity3d Editor引用將其分配給其他組件,而不是搜索它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.