I'm having a rather unusual problem with this code in unity, I keep getting the error "Expressions in statements must only be executed for their side-effects", I went around the web searching for the problem but all the answers were different, the line that is giving the error is (47,44) which is the AnimObj.GetComponent.<Animation>().Play
thanks in advance for the help -_-;
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;
}
In Unity, Animation.Play()
is a function not a variable. You are accessing that as a variable by not including ()
at the end of Play.
It should be:
AnimObj.GetComponent.<Animation>().Play();