Ejemplo n.º 1
0
    void Update()
    {
        Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
        {
            RaycastHit2D hit = Physics2D.Raycast(mousePos, Vector2.down);
            if (hit)
            {
                line.enabled = true;
                line.SetPositions(new Vector3[] { mousePos, hit.point });
                ClumpGenerator clump = hit.collider.GetComponent <ClumpGenerator>();
                if (clump != null)
                {
                    if (Input.GetMouseButton(0))
                    {
                        clump.Circle(hit.point - (hit.normal * 1.5f), 4f, 0.125f);
                    }
                    else
                    {
                        clump.Circle(hit.point, -4f, 0.125f);
                    }
                }
            }
        }
        else
        {
            line.enabled = false;
        }
    }
Ejemplo n.º 2
0
    void SeperateRegion(List <Vector2Int> region)
    {
        //takes a list of tile points and removes it from the current map while creating a new clump with the removed tile values.
        float[,] newMap = new float[size, size];
        foreach (Vector2Int tile in region)
        {
            newMap[tile.x, tile.y] = map[tile.x, tile.y];
            map[tile.x, tile.y]    = 0f;
        }
        GameObject newClump = new GameObject();

        newClump.transform.position = transform.position;
        newClump.transform.rotation = transform.rotation;
        newClump.AddComponent <ClumpMeshGenerator>();
        newClump.GetComponent <MeshRenderer>().material = GetComponent <MeshRenderer>().material;
        newClump.AddComponent <Rigidbody2D>();
        ClumpGenerator newClumpGen = newClump.AddComponent <ClumpGenerator>();

        newClumpGen.size = size;
        newClumpGen.SetMap(newMap);
        newClumpGen.CalculateMass();
        ProcessMap();
        newClumpGen.ProcessMap();
    }