Esempio n. 1
0
    public void StartNewGame()
    {
        if (melonArea == null)
        {
            melonArea = GameObject.FindGameObjectWithTag("MelonArea").GetComponent <BoxArea>();
        }

        if (melons != null && melons.Length > 0)
        {
            for (int i = 0; i < melons.Length; i++)
            {
                if (melons[i] != null)
                {
                    Destroy(melons[i].gameObject);
                }
            }
        }

        melons = new Watermelon[melonCount];
        for (int i = 0; i < melonCount; i++)
        {
            melons[i] = Instantiate(melonPrefabs[Random.Range(0, melonPrefabs.Length)].gameObject).GetComponent <Watermelon>();
            if (i == 0 && (melons[i].Maturity > 1.2f || melons[i].Maturity < 0.8f))
            {
                Destroy(melons[i].gameObject);
                i--;
                continue;
            }

            melons[i].transform.localScale = Vector3.one * Random.Range(melonScaleRange.x, melonScaleRange.y);
            melons[i].transform.rotation   = Quaternion.Euler(0, 0, Random.value * 180 - 90);

            Vector3 pos = Vector3.zero;
            for (int j = 0; j < 100; j++)
            {
                pos = melonArea.GetRandomPoint();
                bool foundSuitablePos = true;
                foreach (var m in melons)
                {
                    if (m == null)
                    {
                        break;
                    }
                    if (((Vector2)(m.transform.position - pos)).sqrMagnitude < melonDistance * melonDistance)
                    {
                        foundSuitablePos = false;
                        break;
                    }
                }

                if (foundSuitablePos)
                {
                    break;
                }
            }

            pos.z = pos.y;
            melons[i].transform.position = pos;
        }
    }
Esempio n. 2
0
    void Spawn(int index)
    {
        if (index < 0 || index >= spawnObjects.Length)
        {
            return;
        }

        var obj  = spawnObjects[index];
        var freq = obj.spawnFreq.Evaluate(passedTime);

        if (Random.value > freq * Time.deltaTime)
        {
            return;
        }

        var scenebound = SceneValues.GetSceneBound();
        var randomX    = Random.Range(scenebound.min.x, scenebound.max.x);
        var point      = new Vector2(randomX, scenebound.max.y + spawnHeight);

        if (spawnArea != null)
        {
            point   = spawnArea.GetRandomPoint();
            point.y = scenebound.max.y + spawnHeight;
        }

        var spawn = ObjectPool.Acquire(obj.obj);

        spawn.transform.position = point;
    }
Esempio n. 3
0
    protected override void InitializeObject(SpawnableObject obj)
    {
        if (area != null)
        {
            (obj as Enemy).TargetPosition = area.GetRandomPoint();
        }
        else
        {
            (obj as Enemy).TargetPosition = transform.position;
        }

        obj.transform.position   = transform.position;
        (obj as Enemy).FromFront = IsFront;
    }