Finally bots can die. Player to. And another fixes.
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Barracuda;
|
||||
using Unity.MLAgents.Policies;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class CharacterFactory : MonoBehaviour
|
||||
{
|
||||
@ -14,7 +16,7 @@ public class CharacterFactory : MonoBehaviour
|
||||
[SerializeField] private GameObject PlayerPrefab;
|
||||
|
||||
private List<GameObject> bots = new List<GameObject>();
|
||||
public GameObject player { get; private set; }
|
||||
public GameObject Player { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@ -27,6 +29,11 @@ public class CharacterFactory : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
print(Player == null);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var attcNum = SettingsReader.Instance.GetSettings.NumOfAttackers;
|
||||
@ -36,20 +43,21 @@ public class CharacterFactory : MonoBehaviour
|
||||
|
||||
if (humanAtc == 1 && humanDef == 1)
|
||||
throw new System.ArgumentException("Can be only one human player");
|
||||
|
||||
for (int i = 0; i < attcNum - humanAtc; i++)
|
||||
InstantiateEntity(Team.Attackers, TypeAI.D0DiskAI,
|
||||
spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)]);
|
||||
for (int i = 0; i < defNum - humanDef; i++)
|
||||
InstantiateEntity(Team.Defenders, TypeAI.D0DiskAI,
|
||||
spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)]);
|
||||
|
||||
if (humanAtc == 1)
|
||||
InstantiateEntity(Team.Attackers, TypeAI.HumanAI,
|
||||
spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)]);
|
||||
if (humanDef == 1)
|
||||
InstantiateEntity(Team.Defenders, TypeAI.HumanAI,
|
||||
spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)]);
|
||||
|
||||
|
||||
for (int i = 0; i < attcNum - humanAtc; i++)
|
||||
InstantiateEntity(Team.Attackers, TypeAI.D0DiskAI,
|
||||
spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)]);
|
||||
for (int i = 0; i < defNum - humanDef; i++)
|
||||
InstantiateEntity(Team.Defenders, TypeAI.D0DiskAI,
|
||||
spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)]);
|
||||
|
||||
GameManager.OnResetScene += ResetCharacters;
|
||||
}
|
||||
|
||||
@ -65,8 +73,9 @@ public class CharacterFactory : MonoBehaviour
|
||||
|
||||
if (typeAi == TypeAI.HumanAI)
|
||||
{
|
||||
print("added player to list");
|
||||
gameobject.GetComponent<Player>().GetCharacter.Team = team;
|
||||
player = gameobject;
|
||||
Player = gameobject;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -101,18 +110,23 @@ public class CharacterFactory : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void ReSpawn(ICharacter character, ref Vector3 pos, ref int startPointId)
|
||||
public void ReSpawn(ICharacter character, GameObject go)
|
||||
{
|
||||
character.ResetCharacter();
|
||||
var team = character.GetCharacter.Team;
|
||||
var ai = character.GetCharacter.TypeAi;
|
||||
NavPoint navPoint;
|
||||
if (team == Team.Attackers)
|
||||
navPoint = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)];
|
||||
else
|
||||
navPoint = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)];
|
||||
|
||||
pos = navPoint.Position;
|
||||
startPointId = navPoint.PointId;
|
||||
go.transform.position = navPoint.Position;
|
||||
if (ai == TypeAI.D0DiskAI)
|
||||
{
|
||||
var mc =go.GetComponent<MovementController>();
|
||||
mc.PointStartID = navPoint.PointId;
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetCharacters()
|
||||
@ -131,9 +145,9 @@ public class CharacterFactory : MonoBehaviour
|
||||
{
|
||||
player.ResetCharacter();
|
||||
if (player.GetCharacter.Team == Team.Attackers)
|
||||
this.player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].Position;
|
||||
this.Player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].Position;
|
||||
else
|
||||
this.player.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].Position;
|
||||
this.Player.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].Position;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user