예제 #1
0
    void SpawnMobs()
    {
        var     sprites = Resources.LoadAll("MobsSprite", typeof(Sprite));
        Vector2 X       = new Vector2(Center.x - Size.x / 2, Center.x + Size.x / 2 + 1);
        Vector2 Y       = new Vector2(Center.y - Size.y / 2, Center.y + Size.y / 2 + 1);

        _mobContainer = new GameObject("MOBCONTAINER");
        foreach (var v in _params)
        {
            if (String.Compare(v.Key, 0, "mob", 0, 3) == 0)
            {
                for (int i = 0; i < int.Parse(v.Value); i++)
                {
                    Vector2 tmp = new Vector2(Random.Range(X.x, X.y), Random.Range(Y.x, Y.y));
                    var     obj = Instantiate(Resources.Load("Prefabs/" + v.Key.Remove(0, 3), typeof(GameObject)) as GameObject, tmp, Quaternion.identity, _mobContainer.transform);
                    _mobs.Add(obj);
                    obj.name = _ng.CreateUsername();
                    obj.GetComponent <SpriteRenderer>().sprite = (Sprite)sprites[Random.Range(0, sprites.Length)];
                    var ia = obj.GetComponent <IaMobs>();
                    ia.DirectionInterval = Random.Range(2, 7);
                    ia.Venere            = Random.Range(0, 20);
                    ia.Life          = Random.Range(200, 1000);
                    ia.Speed         = new Vector2(Random.Range(0.5f, 1.5f), Random.Range(2f, 6));
                    ia.SpeedInterval = new Vector2(Random.Range(0.5f, 1.5f), Random.Range(3, 6));
                }
            }
        }
    }