DemoProductions / shmup

3 stars 2 forks source link

add team class #49

Closed flip40 closed 8 years ago

flip40 commented 8 years ago

Adds Team script. Having a team of none is equivalent to not having the script (see below). It exists for cases where either the team may change explicitly to / from none, whereas not having the script is implicitly not having a team. Example usage:

team = enemy.GetComponent<Team>();
// if has team and team is not friendly with this team
if (team && !team.IsFriendly(this.team)) {
  Attack(enemy);
}

Note that GetCompenent() returns null when there is no component found, and null evaluates to false. The following check if(team) is false in either case of no script, or team == none.

Thoughts on adding an IsEnemy function? It would just be the opposite of IsFriendly, but might be nice for readability over using !IsFriendly...

Also this does not actually add any usage of the added class yet (i.e. no prefabs with it or any checks of it).

ghost commented 8 years ago

Yeah isEnemy seems to read a bit better. Lets make that change later, going to just merge this first