Ejemplo n.º 1
0
    public void Restart()
    {
        if (container)
        {
            //Place all the point away from camera sight
            for (int i = 0; i < points.Count; i++)
            {
                points[i].transform.position = new Vector2(-999, -999);
            }
        }
        //Delete all the vertices points
        if (!(figure is null))
        {
            figure.Clear();
        }

        //Obtain data for the new configuration
        ChangeVertices(true);
        ChangeLength(true);
        ChangeSpeed();
        ChangeProportion(true);

        counter = 0;
        CounterUI.GetComponent <Text>().text = "Iteration: " + counter;
        figure   = new Figure(n, side, prefabPoint);
        vertices = figure.GetVertices();

        //Start position is random choosen
        currentPositionPoint = new Vector2(Random.Range(-side, side), Random.Range(-side, side)) * 1.5f;
        //Instantiate/set position of the point at position:currentPositionPoint
        DrawPoint(currentPositionPoint);
    }
Ejemplo n.º 2
0
    void DrawPoint(Vector2 posVertex)
    {
        GameObject tmp;

        if (counter < points.Count)
        {
            //The pool is still full so just set the position the the point at index counter
            points[counter].transform.position = posVertex;
        }
        else
        {
            //The pool is empty. Create a new object and add it to the pool
            tmp      = Instantiate(prefabPoint, posVertex, Quaternion.identity);
            tmp.name = "Point " + counter;
            tmp.transform.localScale = Vector3.one / 2;
            tmp.transform.SetParent(container.transform);
            points.Add(tmp);
        }
        //Update counter
        counter++;
        //Update UI
        CounterUI.GetComponent <Text>().text = "Iteration: " + counter;
    }