Search Unity

Problem with enemy spawn.

Discussion in 'Editor & General Support' started by HoangPh, Jun 7, 2014.

  1. HoangPh

    HoangPh

    Joined:
    Apr 25, 2014
    Posts:
    18
    So mine enemy spawn system is i creat game object called enemy spawn and enemy Prefabs. The problem is i want when the time in the eSpawn count to 10, it will spawn an enemy which speed is faster than the frist one. But it doesnt work.
    Here is the script which i used in eSpawn
    //////////////////////////////

    public float time = 0;
    public Enemy ene;
    public GameObject enemyPrefab;

    void Update()
    {
    time += Time.deltatime;
    int eCount = GameObject.FindGameObjectsWithTag("Enemy");
    if(eCount <= 0 && time <= 7.9f)
    {
    Instantiate(enemyPrefabs, transform.position , quaternion.identity;
    ene.Level1();
    }
    if(eCount <= 1 && time >= 8.0f)
    {
    Instantiate(enemyPrefabs , transform.position , quaternion.identity);
    ene.SetElevels();
    }
    }

    ///////////////////////////////
    here is the script which i use in EnemyPrefabs;
    ///////////////////////////////

    public float mSpeed;
    public Sprite square;
    public Sprite pentagon;
    int eLevels;
    bool sElevels;

    public void Level1()
    {
    eLevels =1;
    }

    public void SetElevels ()
    {
    Debug.Log(sElevels);
    sElevels = true;
    }

    void Start ()
    {
    if(sElevels)
    {
    eLevels = Random.Range(0,2);
    }
    if(eLevels==1)
    {
    mSpeed = mSpeed/2;
    }
    if(eLevels==0)
    {
    mSpeed = mSpeed *2;
    }
    }

    void Update()
    {
    if(eLevels==1)
    {
    GetComponent<SpriteRenderer>().sprite = square;
    }
    if(eLevels==0)
    {
    GetComponent<SpriteRenderer>().sprite = pentagon;
    }
    rigidbody.velocity = Vector3.up * mSpeed * Time.deltaTime;
    }
    }

    /////////////////////////////
    Please note that i made this script with square first. then the idea to make the enemy move faster pop up in my mind. So i set the Sprite Renderer Component in the EnemyPrefabs to "none" and i put the Square and Pentagon in the script. But its keeps spawning the square. Even i debug,Log(sElevels) = true. Nothing seems to change. And the console report no error so if there is a mispell's mistake in my topic. i've fixed all. Thanks for reading my topic. Thanks for all the help.
     
    Last edited: Jun 7, 2014