示例#1
0
    //Coroutine that spawns enemies
    IEnumerator SpawnEnemy(float delay)
    {
        //Loop while the game is running
        while (true)
        {
            //Wait for the correct delay
            yield return(new WaitForSeconds(delay));

            Enemy.Type newEnemyType = GetEnemyType();


            //Create a new enemy, stock its Enemy
            Enemy newEnemy =
                NGUITools.AddChild(gameObject, Resources.Load("Enemies/" + newEnemyType.ToString()) as GameObject).GetComponent <Enemy>();

            //Initialize it with random speed
            newEnemy.Initialize(newEnemyType, Random.Range(minMovementTime, maxMovementTIme));
            //Set the new random delay
            delay = Random.Range(minInterval, maxInterval);
            //Create a new empty string for destruct code
            string randomCode = "";

            destructCodeChance = GetChance(newEnemyType).hackableChance;

            //If the random is valid, get a random word
            if (Random.Range(0f, 100f) < destructCodeChance)
            {
                newEnemy.hackable = true;
                randomCode        = GetRandomWord();
            }
            else
            {
                newEnemy.hackable = false;
            }
            //Set the enemy's the DestructCode
            newEnemy.SetDestructCode(randomCode);
            //Add the enemy to the list of enemies
            enemies.Add(newEnemy);
        }
    }
    public void SetEnemy(Enemy.Type enemyType)
    {
        if (spriteEnemyList.ContainsKey((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Right * SPRITE_MULTI_COMPASS + Enemy.IMAGE_0))
        {
            return;
        }

        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Right * SPRITE_MULTI_COMPASS + Enemy.IMAGE_0, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_right_0", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Right * SPRITE_MULTI_COMPASS + Enemy.IMAGE_1, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_right_1", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Right * SPRITE_MULTI_COMPASS + Enemy.IMAGE_2, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_right_2", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Left * SPRITE_MULTI_COMPASS + Enemy.IMAGE_0, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_left_0", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Left * SPRITE_MULTI_COMPASS + Enemy.IMAGE_1, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_left_1", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Left * SPRITE_MULTI_COMPASS + Enemy.IMAGE_2, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_left_2", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Top * SPRITE_MULTI_COMPASS + Enemy.IMAGE_0, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_top_0", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Top * SPRITE_MULTI_COMPASS + Enemy.IMAGE_1, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_top_1", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Top * SPRITE_MULTI_COMPASS + Enemy.IMAGE_2, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_top_2", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Bottom * SPRITE_MULTI_COMPASS + Enemy.IMAGE_0, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_bottom_0", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Bottom * SPRITE_MULTI_COMPASS + Enemy.IMAGE_1, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_bottom_1", enemyType.ToString().ToLower())));
        spriteEnemyList.Add((int)enemyType * SPRITE_MULTI_TYPE + (int)Enemy.Compass.Bottom * SPRITE_MULTI_COMPASS + Enemy.IMAGE_2, Resources.Load <Sprite> (string.Format("Textures/enemy_{0}_bottom_2", enemyType.ToString().ToLower())));

        if (enemyType == Enemy.Type.Tengu)
        {
            spriteEnemyWeapon = Resources.Load <Sprite> ("Textures/enemy_weapon");
        }
    }