语句中的表达式只能在产生副作用时执行
Expressions in statements must only be executed for their side effects
我在统一使用这段代码时遇到了一个相当不寻常的问题,我一直收到错误 "Expressions in statements must only be executed for their side-effects",我在网上四处寻找问题,但所有的答案都不一样,那一行给出的错误是 (47,44) 这是 AnimObj.GetComponent.<Animation>().Play
在此先感谢您的帮助 -_-;
var CrossObject : GameObject;
var MechanicsObject : GameObject;
var ClipCount : int;
var ReserveCount : int;
var ReloadAvailable : int;
var AnimObj : GameObject;
var ScriptObj : GameObject;
function Update () {
ClipCount = GlobalAmmo.LoadedAmmo;
ReserveCount = GlobalAmmo.CurrentAmmo;
if (ReserveCount == 0) {
ReloadAvailable = 0;
} else {
ReloadAvailable = 10 - ClipCount;
}
if (Input.GetButtonDown("Reload")) {
if (ReloadAvailable >=1) {
if (ReserveCount <= ReloadAvailable) {
GlobalAmmo.LoadedAmmo += ReserveCount;
GlobalAmmo.CurrentAmmo -= ReserveCount;
ActionReload();
} else {
GlobalAmmo.LoadedAmmo += ReloadAvailable;
GlobalAmmo.CurrentAmmo -= ReloadAvailable;
ActionReload();
}
}
EnableScripts();
}
}
function EnableScripts () {
yield WaitForSeconds(1);
ScriptObj.GetComponent("Fire").enabled=true;
CrossObject.SetActive(true);
MechanicsObject.SetActive(true);
}
function ActionReload () {
ScriptObj.GetComponent("Fire").enabled=false;
CrossObject.SetActive(false);
MechanicsObject.SetActive(false);
AnimObj.GetComponent.<Animation>().Play;
}
在Unity中,Animation.Play()
是函数而不是变量。您通过在播放结束时不包含 ()
来将其作为变量访问。
应该是:
AnimObj.GetComponent.<Animation>().Play();
我在统一使用这段代码时遇到了一个相当不寻常的问题,我一直收到错误 "Expressions in statements must only be executed for their side-effects",我在网上四处寻找问题,但所有的答案都不一样,那一行给出的错误是 (47,44) 这是 AnimObj.GetComponent.<Animation>().Play
在此先感谢您的帮助 -_-;
var CrossObject : GameObject;
var MechanicsObject : GameObject;
var ClipCount : int;
var ReserveCount : int;
var ReloadAvailable : int;
var AnimObj : GameObject;
var ScriptObj : GameObject;
function Update () {
ClipCount = GlobalAmmo.LoadedAmmo;
ReserveCount = GlobalAmmo.CurrentAmmo;
if (ReserveCount == 0) {
ReloadAvailable = 0;
} else {
ReloadAvailable = 10 - ClipCount;
}
if (Input.GetButtonDown("Reload")) {
if (ReloadAvailable >=1) {
if (ReserveCount <= ReloadAvailable) {
GlobalAmmo.LoadedAmmo += ReserveCount;
GlobalAmmo.CurrentAmmo -= ReserveCount;
ActionReload();
} else {
GlobalAmmo.LoadedAmmo += ReloadAvailable;
GlobalAmmo.CurrentAmmo -= ReloadAvailable;
ActionReload();
}
}
EnableScripts();
}
}
function EnableScripts () {
yield WaitForSeconds(1);
ScriptObj.GetComponent("Fire").enabled=true;
CrossObject.SetActive(true);
MechanicsObject.SetActive(true);
}
function ActionReload () {
ScriptObj.GetComponent("Fire").enabled=false;
CrossObject.SetActive(false);
MechanicsObject.SetActive(false);
AnimObj.GetComponent.<Animation>().Play;
}
在Unity中,Animation.Play()
是函数而不是变量。您通过在播放结束时不包含 ()
来将其作为变量访问。
应该是:
AnimObj.GetComponent.<Animation>().Play();