to new git
This commit is contained in:
@ -1,26 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity;
|
||||
|
||||
public class CharacterFactory : MonoBehaviour
|
||||
{
|
||||
private CharacterFactory instance;
|
||||
public CharacterFactory Instance { get { return instance; } }
|
||||
private static CharacterFactory instance;
|
||||
public static CharacterFactory Instance => instance;
|
||||
|
||||
[SerializeField] private List<NavPoint> spawnPointsForDefendersTeam;
|
||||
[SerializeField] private List<NavPoint> spawnPointsForAttackersTeam;
|
||||
[SerializeField] private GameObject AIPrefab;
|
||||
[SerializeField] private GameObject PlayerPrefab;
|
||||
|
||||
private List<GameObject> Bots = new List<GameObject>();
|
||||
private GameObject Player;
|
||||
private List<GameObject> bots = new List<GameObject>();
|
||||
public GameObject player { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = this;
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
Debug.LogError("Only 1 Instance");
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@ -53,7 +55,7 @@ public class CharacterFactory : MonoBehaviour
|
||||
{
|
||||
var gameobject = GameObject.Instantiate(
|
||||
typeAi == TypeAI.HumanAI ? PlayerPrefab : AIPrefab,
|
||||
spawnPoint.position,
|
||||
spawnPoint.Position,
|
||||
Quaternion.identity);
|
||||
gameobject.SetActive(true);
|
||||
if (team == Team.Attackers)
|
||||
@ -64,35 +66,49 @@ public class CharacterFactory : MonoBehaviour
|
||||
if (typeAi == TypeAI.HumanAI)
|
||||
{
|
||||
gameobject.GetComponent<Player>().GetCharacter.Team = team;
|
||||
Player = gameobject;
|
||||
player = gameobject;
|
||||
}
|
||||
else
|
||||
{
|
||||
gameobject.GetComponent<NPC>().GetCharacter.Team = team;
|
||||
gameobject.GetComponent<MovementController>().CurrentNavPoint = spawnPoint;
|
||||
Bots.Add(gameobject);
|
||||
gameobject.GetComponent<MovementController>().PointStartID = spawnPoint.PointId;
|
||||
bots.Add(gameobject);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReSpawn(ICharacter character, ref Vector3 pos, ref int startPointId)
|
||||
{
|
||||
character.ResetCharacter();
|
||||
var team = character.GetCharacter.Team;
|
||||
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;
|
||||
}
|
||||
|
||||
private void ResetCharacters()
|
||||
{
|
||||
foreach (var bot in Bots)
|
||||
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;
|
||||
bot.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].Position;
|
||||
else
|
||||
bot.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].position;
|
||||
bot.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].Position;
|
||||
}
|
||||
Player player;
|
||||
if (TryGetComponent<Player>(out player))
|
||||
{
|
||||
player.ResetCharacter();
|
||||
if (player.GetCharacter.Team == Team.Attackers)
|
||||
Player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].position;
|
||||
this.player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].Position;
|
||||
else
|
||||
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