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