Ejemplo n.º 1
0
    public void SpawnMesh()
    {
        int   randSides = Random.Range(3, 7);
        float spawnX    = Random.Range(50f, _screenWidth - 50f);

        spawnCoord = Camera.main.ScreenToWorldPoint(new Vector2(spawnX, _screenHeight + 50f));
        spawnCoord = new Vector3(spawnCoord.x, spawnCoord.y, 0);

        ShapeGenerator existingMesh = availableMesh.Find(x => x.GetSides == randSides);

        if (existingMesh == null)
        {
            //Debug.Log("Polygon sides: " + randSides + " not in pool");

            ShapeGenerator mesh = Instantiate(meshPrefab, spawnCoord, Quaternion.identity);
            mesh.GetComponent <ICreatePolygon>().CreatePolygon(randSides, 0.5f);
            mesh.GetComponent <ICreatePolygon>().ChangeRandomColor();
            mesh.InitMove();
        }
        else
        {
            availableMesh.Remove(existingMesh);
            existingMesh.gameObject.SetActive(true);
            existingMesh.transform.position = spawnCoord;
            existingMesh.GetComponent <ICreatePolygon>().ChangeRandomColor();
            existingMesh.InitMove();
        }
    }