Spawn Enemy with Distance between each other

I Looking on internet to how to create a distance between each enemy when spawning cause the enemy that i am spawning that i have right now overlapping each other and very close to each other.i find that i have use vector.distance and for loop. but i don’t know if it going to work or evening start the script.i just want a space between the enemy man making a space shooter and the enemy coming like snake but there overlapping each which i don’t like

So what you are actually looking for is a “follow en-trail” script if you want to make a snake like pattern of enemies.

There are various tutorials out there to make enemies all follow in a chain, but generally what you do is have each enemy point to the next one up the line, and each enemy agent tries to stay “the right distance” from the enemy ahead.

yeah please do you know how to create what i asking for i can’t seems to find any tutorial online

Are you spawning enemies all at once or over time?

i have a specific enemy that need distance between each when spawn so every countdown of 5 second a new set of enemy will be spawning so when i want to spawn that specific enemy i distance between them or there so overlapp
like this image that i have and also i want to know if you know how to create movement like this in the image that i will have below

2617691--183715--vlcsnap-2016-04-27-20h23m20s078.png 2613778--183347--vlcsnap-2016-04-27-20h24m11s550.png 2617691--183717--vlcsnap-2016-04-27-20h25m39s494.png 2617691--183718--vlcsnap-2016-04-27-20h25m30s034.png

I am not sure as to what kind of game you are trying to make, so I will assume it will be similar to the pictures. I think you might want to look int ray casting. Pretty much what you would do is when you try to spawn an enemy at a fixed location the rays would detect if there is an object nearby. you could then use those to then calculate where to instantiate the enemy. Assassins Creed is a good example of the various uses of ray casts, they can also be used in stealth games to give enemies a field of view. they could also be used to detect ledges when jumping or various parkour actions. As for the movement I am not sure what you mean. Are you talking about the way the enemies move in a twisty single file line or just the randomness in general?

Pretty much what you would do is spawn one, keep sending out rays until the first one is far enough away, spawn another, repeat. doing this will allow you to customize what enemy is in each group so there can be different types if you instantiate them from a cutomizable array of gameobjects. Another, simpler but also limiting way is to crate prefabs of the different enemy groups and just spawn those off screen and they will just move into the camera view as a group.

okay cool did you seen the image that i send you, did you see the distance between and plane and alien ship i making spaceshooter i make to know how to me curve movement so that the enemy can follow it

I was digging around on the internet and found this:
http://itween.pixelplacement.com/examples.php
I have never used it myself but it looks like what you are looking for.

i try it bro but i find that it very hard for the enemy to rotate toward the path so u quit using that

i was wondering if simple waypoint system might work

This might help get your enemies from point A to point B while also giveing them AI to avoid any stage obstacles.
https://unity3d.com/learn/tutorials/modules/beginner/navigation/navmesh-agent

ahahahh do you even know what type of game i am making it a space shooter game bro rite now i am working on the waves spawning script

I am aware of that. I am not trying to directly answer your question because I don’t have any code to go off of. Right now I am just trying to point you in the right direction with various methods. To directly answer your question, all you need is a prefab holding an entire wave and just instantiate it every 5 seconds. I assume you want more than just that so I need to see code of what you have already done before I can actually help you.

We used a waypoint system (an array of Transforms), then made a smooth Catmull Rom curve using Interpolate.cs.

I move ships along the waypoints using Vector3.MoveTowards. If you take the difference between the next waypoint and the previous waypoint, you get a vector that is the “forward” direction. I use this with Transform.LookAt to point ships in the right direction.

(Eventually, we moved to a custom lerp function instead of Vector3.MoveTowards)

All enemies in a wave follow the exact same path, they just start a half second behind each other. This is the only thing we did to keep enemies some distance apart.

I like @Collin_Patrick idea with the prefabs. A wave prefab consists of one curve, and sends ships along the curve one at a time.

I like this blog as an example of someone else who made a SHMUP (not with Unity).

partner rite now i am tired of trying to making a game i trying for 2 years now and 4 months since we in a new month now i trying to make a level unlock script, i want it to be like this if high score is greater or equal to sum amount score unlock level and set the star rating to three and if any score if low lets say 500 out 1000 give player two star but unlock level still and also i have 5 stage like this stage 1 have one to five level and the last level have a last boss if i defeated the boss i would unlock the next stage than unlock level in that specific sorry for sounding corrupt but this the best way i can explain what i want to create .i trying my best to make the script or even implement it i find tutorial on youtube but there not giving me what i want so if i success when my game i am going create a youtube too i don’t other trying to be indie developer to suffer like me. i notice these people making these script or code to please there self not to help other.
this Spawn wave script i have when i kill the last enemy in the array it keep loop from the first wave i don’t that i want to stop when it reach it last wave in the array;
these function cause it to restart and go to the next array after i kill a sum amount of enemy in a array if you understand what i am trying to get at.
this line that i can’t fix

void WaveCompleted ()
    {
        Debug.Log ("Wave Completed!");
        state = SpawnState.COUNTING;
        waveCountdown = timeBetweenWaves;

        if (nextWave + 1 > waves.Length - 1)
        {
            nextWave = 0;
            Debug.Log ("All  WAVES COMPLETE! looping...");
        }

        else {
            nextWave++;
            Debug.Log ("Starting next Waves");
        }

        if (waves.Length > -1)
        {
       
            StopCoroutine(SpawnWave(waves[nextWave]));;
            Debug.Log ("Stop Spawning ");
        }
    }

here the entire script another problem i want to each wave too have there own spawn point of i have some enemy coming from the side of the screen i just don’t know how to implement that specific function.
so please if you can help me that would be great.

using UnityEngine;
using System.Collections;

public class Waves : MonoBehaviour {

    public enum SpawnState
    {
        SPAWNING, WAITING, COUNTING
    };


    [System.Serializable]
    public class Wave
    {

        public string name;
        public Transform enemy;
        public int count;
        public float rate;
   

    }


    public Transform[] SpawnPoint;
    public Wave[] waves;
    private int nextWave = 0;
    public int NextWave
    {
        get{ return nextWave + 1;}
    }

    public float timeBetweenWaves = 5f;
    public float waveCountdown;
    public float WaveCountdown
    {
        get{ return waveCountdown;}
    }

    private float searchCountDown = 1f;
    private SpawnState state = SpawnState.COUNTING;
    public SpawnState State
    {
        get { return state;}
    }
    void Start () {
        if (SpawnPoint.Length == 0) {
            Debug.LogError ("No Spawn points reference.");

                waveCountdown = timeBetweenWaves;

        }
       
   
    }
   
    // Update is called once per frame
    void Update () {
        if (State == SpawnState.WAITING) {
            if (!EnemyIsAlive ()) {
                WaveCompleted ();
            }
            else
            {
                return;
            }
        }

        if (waveCountdown <= 0) {
            if (state != SpawnState.SPAWNING)
            {
               
                StartCoroutine(SpawnWave(waves[nextWave]));
               
            }
        }
        else
        {
            waveCountdown -= Time.deltaTime;
        }
   
    }


    void WaveCompleted ()
    {
        Debug.Log ("Wave Completed!");
        state = SpawnState.COUNTING;
        waveCountdown = timeBetweenWaves;

        if (nextWave + 1 > waves.Length - 1)
        {
            nextWave = 0;
            Debug.Log ("All  WAVES COMPLETE! looping...");
        }

        else {
            nextWave++;
            Debug.Log ("Starting next Waves");
        }

        if (waves.Length > -1)
        {
       
            StopCoroutine(SpawnWave(waves[nextWave]));;
            Debug.Log ("Stop Spawning ");
        }
    }

    bool EnemyIsAlive ()
    {
        searchCountDown -= Time.deltaTime;
        if(searchCountDown <= 0f)
        {
            searchCountDown = 1f;
            if (GameObject.FindGameObjectWithTag ("Enemy") == null)
            {
                return false;
            }
        }
        return true;
    }

    IEnumerator SpawnWave(Wave _wave)
    {
        Debug.Log ("Spawning Wave: " + _wave.name);
        state = SpawnState.SPAWNING;
        for (int i = 0; i < _wave.count; i++)
        {
            SpawnEnemy (_wave.enemy);
            yield return new WaitForSeconds (1f / _wave.rate);
        }

        state = SpawnState.WAITING;
        yield break;
    }

    void SpawnEnemy (Transform _enemy)

    {
        Debug.Log("Spawning Enemy: " + _enemy.name);
        Transform _sp = SpawnPoint [Random.Range (0, SpawnPoint.Length)];

        Instantiate (_enemy, _sp.position, _sp.rotation);
    }
}

Your first problem handling the # of stars and unlocking levels is an easy fix. This script assumes that you have a gameobject for each level that this script can be attached to. I should also note that this script is untested and will likely give a few errors, it is only meant to be a guide not a solution.

You will attach this script to each level gameobject:

public class LevelController : MonoBehaviour{
    private bool locked;//determins if this level is locked or not (the first level will be set to false in inspector and all other levels will be true
    public int levelScore;//Score required for 3 stars, edit in inspector
    private int score;//the players score
    private int stars;//# of stars earned on level
    public GameObject nextLevel;//put the gameobject of the next level here (the gameobject that also has this script)

    void Update(){
        
        if (locked = true) {
            //code to deactive UI/GUI button so it cannot be pressed
        }
        //////////
        ///These if statements decide how many stars a level has
        ///based on the score the player got compared
        ///to the preset level score.
        //////////
        if (score >= levelScore) {
            stars = 3;
            nextLevel.GetComponent<LevelController>().locked = false;
        } else if (score > 500 && score < levelScore) {
            stars = 2;
            nextLevel.GetComponent<LevelController>().locked = false;
        } else if (score < 500) {
            stars = 1;
        } else if (score <= 0) {
            stars = 0;
        }

        /////////
        /// These if statements will update the # of
        /// stars that appear on this level.
        ////////
        if (stars = 1) {
            //code that changes the # of stars on the screen
        }
        if (stars = 2) {
            //code that changes the # of stars on the screen

        }
        if (stars = 3) {
            //code that changes the # of stars on the screen

        }
    }

}

As for your other problems in the waves scripts, I will need a better more detailed explanation to help you.

well i fix the waves bro it not need do you know how to save a weapon on to the next level
like this i have a current weapon and save it to the next level and have a unlock weapon script. which i have a gameobject and if the player collide with this gameobject unlock a new weapon and change the current weapon with the new weapon

I am not sure how you are saving your game data but it sounds like you could just do the same thing and just save the last used weapon. Do you use binary or player prefs?