Hi to all!
In my game, I need the consequences of player actions (i.e. which functions are triggered) to be highly customizable. I had started out like this (abstract example, ResponseModes is an enum):
function PlayerTappedTarget()
{
if(responseMode == ResponseModes.Nice)
{
TellPlayerSomethingNice();
score++;
}
else if(responseMode == ResponseModes.Antagonist)
{
TellPlayerSomethingNasty();
BlockControls();
score = -1000000;
}
else if(responseMode == ResponseModes.None//and so on
{}
}
The problem with this approach is that I need lots of ResponseModes, and it seemed a bit clumsy. So I’m trying another approach:
enum Responses
{
TellPlayerSomethingNice,
IncreasePlayerScore,
TellPlayerSomethingNasty,
DecreasePlayerScore,
etc...
}
public var tapResponses : List.<Responses>; //defined in the inspector, may be modified at runtime
function PlayerTappedTarget()
{
DoResponsesList(tapResponses);
}
function DoResponsesList(responseList : List.<Responses>)
{
for(response in responseList)
{
switch(response)
{
case Responses.TellPlayerSomethingNice:
TellPlayerSomethingNice();
break;
case Responses.IncreasePlayerScore:
score++;
break;
//and so on
}
}
}
Is there a more elegant way to do this? I have about 25 different Responses, in case…
Thanks in advance for your insights!