Enemy behaviour

i want to spawn the enemy in a different position when he dies but it always shows up at the center of the game behind the background and he doesn’t move.

Enemy script
public float _Speed = 2.0f;
public GameObject EnemyAi;

// Use this for initialization
void Start ()
    transform.position = new Vector3(transform.position.x, transform.position.y, 0);

// Update is called once per frame
void Update ()
    transform.Translate(Vector3.down * Time.deltaTime * _Speed);

    if (transform.position.y < -6.16f)

        Vector3 position = new Vector3(Random.Range(-8.0f, 6.05f), 0, Random.Range(8.0f, 6.05f) * Time.deltaTime);
        Instantiate(EnemyAi, position, Quaternion.identity);
        transform.Translate(Vector3.down * Time.deltaTime * _Speed);


Hi, I see you used Destroy(gameObject); before you Instantiate a new object. It is better if you put it at the end.

Then why are you creating a vector with random x and z components? When the Enemy spawns the z position will be set to 0 in the Start function. Maybe you wanted to set random x and y components.

I think you could also delete the transform.Translate(Vector3.down * Time.deltaTime * _Speed); line in the if condition. If you destroy the object you didn’t need it anymore.

Yea I wanted to set random x and y components sorry I’m a noon at this still and I did had the Destroy (gameobject) at the end but cause I was having that pobrem I moved before instatiate to see if it would work