Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Spawner doesnt spawn entitys

Discussion in 'Scripting' started by MasouriSama, Mar 24, 2020.

  1. MasouriSama

    MasouriSama

    Joined:
    Mar 11, 2020
    Posts:
    4
    "Well as the title says i have a spawner script thats running without any errors but nit just wont spawn entitys,
    pls can anyone help me.

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

    public class EnemySpawning : MonoBehaviour{

    public GameObject[] Enemy;
    public Vector3 spawnValues;
    public float spawnWait;
    public float spawnMostWait;
    public float spawnLeastWait;
    public int startWait;

    private int randEnemy;

    void start (){
    StartCoroutine(Spawner());
    }

    void Update (){
    spawnWait = Random.Range (spawnLeastWait, spawnMostWait);
    }

    IEnumerator Spawner (){
    yield return new WaitForSeconds (startWait);

    while (true){
    randEnemy = Random.Range (0, 2);

    Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), 1, Random.Range (-spawnValues.z, spawnValues.z));

    Instantiate (Enemy[randEnemy], spawnPosition + transform.TransformPoint (0, 0, 0), Quaternion.identity);

    yield return new WaitForSeconds (spawnWait);
    }

    }

    }
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Hey, please use code tags to post code examples.
    You spelled 'Start()' with a lower case letter, so it's not the method called by Monobehaviour, so your Coroutine does not get started.
     
  3. MasouriSama

    MasouriSama

    Joined:
    Mar 11, 2020
    Posts:
    4
    i will do that in future thank u, and yes that was acctually the problem so thank u again.