kirill loh

This commit is contained in:
2022-04-18 10:53:21 +07:00
parent 5fb554f098
commit e1d0bbc1eb
12 changed files with 88 additions and 31 deletions

View File

@ -12,7 +12,8 @@ public class CharacterFactory : MonoBehaviour
[SerializeField] private GameObject AIPrefab;
[SerializeField] private GameObject PlayerPrefab;
private List<GameObject> Players;
private List<GameObject> Bots = new List<GameObject>();
private GameObject Player;
private void Awake()
{
@ -44,6 +45,8 @@ public class CharacterFactory : MonoBehaviour
if (humanDef == 1)
InstanciateEntity(Team.Defenders, TypeAI.HumanAI,
spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)]);
GameManager.OnResetScene += ResetCharacters;
}
private void InstanciateEntity(Team team, TypeAI typeAi, NavPoint spawnPoint)
@ -52,8 +55,40 @@ public class CharacterFactory : MonoBehaviour
typeAi == TypeAI.HumanAI ? PlayerPrefab : AIPrefab,
spawnPoint.position,
Quaternion.identity);
var character = gameObject.GetComponent<ICharacter>();
character.GetCharacter.Team = team;
gameobject.SetActive(true);
if (typeAi == TypeAI.HumanAI)
{
gameobject.GetComponent<Player>().GetCharacter.Team = team;
Player = gameobject;
}
else
{
gameobject.GetComponent<NPC>().GetCharacter.Team = team;
gameobject.GetComponent<MovementController>().currentPosition = spawnPoint;
Bots.Add(gameobject);
}
}
private void ResetCharacters()
{
foreach (var bot in Bots)
{
var npc = bot.GetComponent<NPC>();
npc.ResetCharacter();
if (npc.GetCharacter.Team == Team.Attackers)
bot.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].position;
else
bot.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].position;
}
var player = Player.GetComponent<Player>();
if (player != null)
{
player.ResetCharacter();
if (player.GetCharacter.Team == Team.Attackers)
Player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].position;
else
Player.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].position;
}
}
}