Unity and Second Steps

I’ve not been completely been informing this quiet corner of the interwebs of a little venture — equally as quiet — that saw me in the aftermath of shelving Zombots. The (temporary?) abandonment of Zombots was a decision come to all those concerned. If I were honest — and I was — Zombots wasn’t hitting the kind of obsessive note in me, and I couldn’t get to the same level of passion when I was developing Janus. So, it was just a matter of time before I had to drop it.

However, the upside to Zombots was that it allowed me to play, to get my feet wet with the first steps into Unity. Zombots allowed me to experiment and get used to its system and its scripting without having to concern myself too much with the structure of the game. It taught me a lot of things, and that’s why I’ve gathered more confidence in trying to make a game inspired by an old one from my childhood.

When I look down, I find the task so daunting that I feel like I’m crazy sinking so much time on this. But I don’t want to look down, I don’t want to rationalise potential. I don’t want to be distracted by anything.

On another note, and the primary reason for this post, I humbly managed to implement my first custom interface called ICombatMessage. I hooked it up this way:

public interface ICombatMessage extends IEventSystemHandler
{
    function OnBeingAttacked(attacker:GameObject);
}

… extending from IEventSystemHandler is required. This registers _OnBeingAttacked_ as an EventFunction under ICombatMessage.

Now the next bit is implementing that; so in the CombatClass.js, where the event function needs to fire (to inform the target that it is being shot at):

ExecuteEvents.Execute.<ICombatMessage>(target,null,function (x,y) { x.OnBeingAttacked(shooter);});

… the syntax of which confused me at first because there were no Unityscript examples (only C#). At any rate, the .<ICombatMessage> refers to the Type (ie <> denotes Type of the Type that’s put inside). Then the rest are almost self-explanatory. The functor, or what I see as a lambda function, is the EventFunction and based on the linked docs, an EventFunction always carries the handles (which refers to the function I had defined — OnBeingAttacked) and a BaseEventData object, which is something I didn’t use.

So with that in place, I implement ICombatMessage in CombatantClass.js:

function OnBeingAttacked(attacker:GameObject)
{
   Debug.Log("HELP!");
}