I am getting tons of errors regarding different things, and I've checked everything, which all seems to be fine

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ZombieSpawnScript : MonoBehaviour
{
    private bool xPositive, yPositive;
    private float xClosestBorder, xFarthestBorder;
    private float yClosestBorder, yFarthestBorder;
    [SerializeField] private float closestSpawn, farthestSpawn;

    [SerializeField] private GameObject zombiePrefab;
    
    private void Start()
    {
        StartCoroutine(SpawnZombie(1, 2));
    }   

    private IEnumerator SpawnZombie(int amount, float period)
    {
        while(true)
        {
            
            private float spawnPointX = Random.Range(-1f, 1f);
            private float spawnPointY = Random.Range(-1f, 1f);

            if(spawnPointX > 0)
            {
                xPositive = true;
            } else if(spawnPointX < 0)
            {
                xPositive = false;
            }

            if(spawnPointY > 0)
            {
                yPositive = true;
            } else if(spawnPointY < 0)
            {
                yPositive = false;
            }
            
            if(xPositive)
            {
                xClosestBorder = closestSpawn;
                xFarthestBorder = farthestSpawn;
            } else 
            {
                xClosestBorder = -closestSpawn;
                xFarthestBorder = -farthestSpawn;
            }

            if(yPositive)
            {
                yClosestBorder = closestSpawn;
                yFarthestBorder = farthestSpawn;
            } else 
            {
                yClosestBorder = -closestSpawn;
                yFarthestBorder = -farthestSpawn;
            }

            for(int i = 0; i < amount; i ++)
            {
                Instantiate(zombiePrefab, new Vector3(Random.Range(xClosestBorder, xFarthestBorder), 0.5f, Random.Range(yClosestBorder, yFarthestBorder)));
            }

            yield return new WaitForSeconds(period);
        }
    }
}

So I’m getting tons of errors regarding different things like “Invalid tokens” (for operators and assignment equal symbols), paranthesis and brackets needing a closing part, missing semicolons, and invalid expressions such as “else”. Does anyone know how to deal with this? Or have I missed something?

Hi @SJ_TRPD

You are trying to declare a couple of variables with access modifier inside of SpawnZombie method

        private float spawnPointX = Random.Range(-1f, 1f);
        private float spawnPointY = Random.Range(-1f, 1f);

If you want those variables are globals you should declare it out of the method scope
or
you can declare as local variables, just remove ‘private’ modifier on declarations

after this, you’ll get a issue when you called Instantiate,
you should inform a rotation using a Quaternion like this:

Instantiate(zombiePrefab, new Vector3(Random.Range(xClosestBorder, xFarthestBorder), 0.5f, Random.Range(yClosestBorder, yFarthestBorder)), Quaternion.identity);

you can see more details at

I hope to help

Oh, that seems simple enough. Thanks for the help!