void Respawn() { respawnTimer += Time.deltaTime; if (respawnTimer >= respawnDelay) { respawnTimer = 0f; List <Transform> possibleRespawns = new List <Transform>(); foreach (Transform spawn in spawnRegions) { SpawnCheck check = spawn.GetComponent <SpawnCheck>(); if (check.IsFree()) { possibleRespawns.Add(spawn); } } int spawnToGoIndex = Random.Range(0, possibleRespawns.Count); Transform spawnToGo = possibleRespawns[spawnToGoIndex]; transform.position = CloneVector3(spawnToGo.position); chasing = null; } }
public override IEnumerator SlowUpdate() { if (IsServer) { spawnPositions = GameObject.FindGameObjectsWithTag("spawn"); //checking for height to assign spawn check script if (spawnPositions[0].transform.position.y > spawnPositions[1].transform.position.y) { foodSpawn = spawnPositions[0].transform.position; cookSpawn = spawnPositions[1].transform.position; foodSpawnCheck = spawnPositions[0].GetComponent <SpawnCheck>(); cookwareSpawnCheck = spawnPositions[1].GetComponent <SpawnCheck>(); } else { foodSpawn = spawnPositions[1].transform.position; cookSpawn = spawnPositions[0].transform.position; foodSpawnCheck = spawnPositions[1].GetComponent <SpawnCheck>(); cookwareSpawnCheck = spawnPositions[0].GetComponent <SpawnCheck>(); } canCookSpawn = false; canFoodSpawn = false; } if (IsClient) { } while (IsServer) { canFoodSpawn = !foodSpawnCheck.isOccupied; canCookSpawn = !cookwareSpawnCheck.isOccupied; yield return(new WaitForSeconds(0.4f)); //potentially slower } }