Exemplo n.º 1
0
    public void SetType(EnemyParser.EnemyType type)
    {
        this.type = type;
        EnemyParser.EnemyInfo info = EnemyParser.GetEnemyInfo(type);

        weapon.SetDamage(info.damage);
        health.SetMax(info.health);
        reloadTime = info.reloadTime / 1000;

        Material pickedMaterial = null;

        foreach (var material in materials)
        {
            if (material.type != type)
            {
                continue;
            }
            pickedMaterial = material.material;
            break;
        }
        if (pickedMaterial != null)
        {
            meshRenderer.material = pickedMaterial;
        }
    }
Exemplo n.º 2
0
    void PrepareWave()
    {
        Regex regex = new Regex("\\((.*?), (.*?), (.*?)\\) (.*?)$", RegexOptions.Multiline);

        if (stepCoroutine != null)
        {
            StopCoroutine(stepCoroutine);
            stepCoroutine = null;
        }

        ProjectileController[] projectiles = FindObjectsOfType <ProjectileController>();


        foreach (var p in projectiles)
        {
            p.End();
        }

        player.SetCanShoot(!blockShootingAtStart);

        MatchCollection matches = regex.Matches(mapFiles[currentMap % mapFiles.Count].text);

        lastStep = Time.time - stepInterval;

        foreach (Match m in matches)
        {
            Vector3 target             = new Vector3(float.Parse(m.Groups[1].Value, CultureInfo.InvariantCulture), float.Parse(m.Groups[2].Value, CultureInfo.InvariantCulture), float.Parse(m.Groups[3].Value, CultureInfo.InvariantCulture));
            EnemyParser.EnemyType type = (EnemyParser.EnemyType)System.Enum.Parse(typeof(EnemyParser.EnemyType), m.Groups[4].Value);

            GameObject nextEnemy = ObjectPool.SpawnObject(ObjectPool.enemy, new Vector3(Random.Range(-8, 8), 0, Random.Range(12, 15)));

            var controller = nextEnemy.GetComponent <EnemyController>();
            controller.SetTargetPosition(target);
            controller.SetType(type);
            controller.OnDestinationReached += ShipApproached;
            controller.waveManager           = this;

            var mover = nextEnemy.GetComponent <Mover>();
            mover.speed          = new Vector2(5, 5);
            mover.alignment      = Mover.MoveAlignment.Align;
            mover.rotationOffset = 180f;

            nextEnemy.GetComponent <Health>().OnDepletion += KillEnemy;

            currentWave.Add(nextEnemy);
            approachingShips.Add(nextEnemy);
        }
    }