- Home /
Question by
CTatz · Feb 11, 2014 at 01:04 AM ·
arrayfunctiondelegatenon-static
Call function from array without it being static
I have an array that holds a list of functions, however my code wont let me call those functions without them being static classes, which I do not want.
I'm a novice and haven't done a lot of code with delegates and I'm not fully aware of where I went wrong or how to work around / fix it.
Constructor:
delegate void ActFunc();
private ActFunc[] actionFunctions = {CallMoveObject, CallScreamAttack};
Where it calls from:
for(int i = 0; i < actionValues.Length; i++){
if( r >= actionValues[i] ){
actionFunctions[i]();
break;
}
}
Error from unity:
error CS0236: A field initializer cannot reference the nonstatic field, method, or property 'RockGolem.CallMoveObject()'
Thanks for the help!
Comment