Exemple #1
0
        public static void Respawn(PlayerControllerBase playercontroller)
        {
            PawnBase   pawn = playercontroller.possedPawn.GetComponent <PawnBase>();
            SpawnPoint pawnSpawnLocation;

            if (gamemode.mapData.FindSpawnPointForPawn(pawn, out pawnSpawnLocation))
            {
                pawnSpawnLocation.spawncount++;
                Transform spawnTransform = pawnSpawnLocation.GetSpawnPoint;
                pawn.transform.position = spawnTransform.position;
                pawn.transform.rotation = spawnTransform.rotation;
            }
        }
        public void Posses(PawnBase targetPawn)
        {
            if (targetPawn == null)
            {
                Debug.LogError($"{this.ToString()} attempted to posses a null object");
                return;
            }
            if (possedPawn != null)
            {
                possedPawn.UnPossessInternal(this);
            }

            if (targetPawn.PossessInternal(this))
            {
                possedPawn = targetPawn;
            }
        }
Exemple #3
0
        public GameObject SpawnPlayer(PlayerControllerBase playercontroller)
        {
            // get prefab
            GameObject newPawn = GameObject.Instantiate(PlayerPawn);
            PawnBase   pawn    = newPawn.GetComponent <PawnBase>();

            playercontroller.Posses(pawn);

            SpawnPoint pawnSpawnLocation;

            if (mapData.FindSpawnPointForPawn(pawn, out pawnSpawnLocation))
            {
                pawnSpawnLocation.spawncount++;
                Transform spawnTransform = pawnSpawnLocation.GetSpawnPoint;
                newPawn.transform.position = spawnTransform.position;
                newPawn.transform.rotation = spawnTransform.rotation;
            }

            return(newPawn);
        }
Exemple #4
0
        public bool FindSpawnPointForPawn(PawnBase pawn, out SpawnPoint spawnPoint)
        {
            List <SpawnPoint> possibPoints = new List <SpawnPoint>();

            foreach (SpawnPoint PossibleSpawnPoint in spawnPoints)
            {
                if (PossibleSpawnPoint.CanPawnSpawnAtPoint(pawn))
                {
                    possibPoints.Add(PossibleSpawnPoint);
                }
            }

            if (possibPoints.Count == 0)
            {
                Debug.LogError($"Failed to find spawnpoint for '{pawn.ToString()}'");
                spawnPoint = null;
                return(false);
            }

            SpawnPoint smallPoint = null;

            foreach (var point in possibPoints)
            {
                if (smallPoint == null)
                {
                    smallPoint = point;
                    continue;
                }

                if (smallPoint.spawncount > point.spawncount)
                {
                    smallPoint = point;
                }
            }

            spawnPoint = smallPoint;

            return(true);
        }
 /// <summary>
 /// Checks if the given pawn is allowed to spawn at this location
 /// With inheritance you can modify the pawn requirements
 /// </summary>
 /// <param name="pawn">pawn that tries to spawn</param>
 /// <returns>returns true when the player is allowed to spawn here</returns>
 public virtual bool CanPawnSpawnAtPoint(PawnBase pawn)
 {
     return(true);
 }