public void UpdateTypeOfPlay() { if (this == this.team.Player.Controlled) { this.typeOfPlayer = TYPEOFPLAYER.OFFENSIVE; invariantMove = false; return; } float dist = Mathf.Abs(this.team.Player.Controlled.transform.position.z - this.transform.position.z); //Vector3.SqrMagnitude(this.team.Player.Controlled.transform.position - this.transform.position); int nb = this.team.GetNumberOffensivePlayer(); bool tooNear = false; foreach (Unit u in this.team) { if (u != this && u != this.team.Player.Controlled && u.typeOfPlayer != TYPEOFPLAYER.OFFENSIVE) { if (Mathf.Abs(this.team.Player.Controlled.transform.position.z - u.transform.position.z) < dist) { tooNear = true; } } } if (tooNear) { this.typeOfPlayer = TYPEOFPLAYER.DEFENSE; invariantMove = false; } else if (!tooNear && nb < this.oTS.nbOffensivePlayer) { this.typeOfPlayer = TYPEOFPLAYER.OFFENSIVE; invariantMove = false; } // QUICK FIX if (this != team.Player.Controlled && team.GetNumberOffensivePlayer() > this.oTS.nbOffensivePlayer + 1) { this.typeOfPlayer = TYPEOFPLAYER.DEFENSE; } }
public void UpdateTypeOfPlay() { if (this == this.team.Player.Controlled) { this.typeOfPlayer = TYPEOFPLAYER.OFFENSIVE; invariantMove = false; return; } float dist = Mathf.Abs(this.team.Player.Controlled.transform.position.z - this.transform.position.z);//Vector3.SqrMagnitude(this.team.Player.Controlled.transform.position - this.transform.position); int nb = this.team.GetNumberOffensivePlayer(); bool tooNear = false; foreach (Unit u in this.team) { if (u != this && u != this.team.Player.Controlled && u.typeOfPlayer != TYPEOFPLAYER.OFFENSIVE) { if (Mathf.Abs(this.team.Player.Controlled.transform.position.z - u.transform.position.z) < dist) { tooNear = true; } } } if (tooNear) { this.typeOfPlayer = TYPEOFPLAYER.DEFENSE; invariantMove = false; } else if (!tooNear && nb < this.oTS.nbOffensivePlayer) { this.typeOfPlayer = TYPEOFPLAYER.OFFENSIVE; invariantMove = false; } // QUICK FIX if (team.GetNumberOffensivePlayer() >= 4) { this.typeOfPlayer = TYPEOFPLAYER.DEFENSE; } }