Beispiel #1
0
    public Blobb getNeighbor(Vector3 checkDirection, blobb_Id id)
    {
        RaycastHit hitInfo;

        if (Physics.Raycast(transform.position, checkDirection, out hitInfo, 0.8f))
        {
            if (hitInfo.collider != null)
            {
                Blobb b = hitInfo.collider.GetComponent <Blobb>();
                if (b != null && b.id == id)
                {
                    return(b);
                }
            }
        }
        return(null);
    }
Beispiel #2
0
    //generate blomb in all space of grid
    void fillBoard()
    {
        blobb_Id[] previousLeft  = new blobb_Id[height];
        blobb_Id   previousBelow = 0;

        //if (blobblist.Length < 1) return;
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                List <GameObject> possibleBlobbs = new List <GameObject>();
                possibleBlobbs.AddRange(blobblist);

                //check for automatic delete
                for (int k = possibleBlobbs.Count - 1; k >= 0; k--)
                {
                    blobb_Id idToCheck = possibleBlobbs[k].GetComponent <Blobb>().id;
                    if (idToCheck == previousLeft[j] || idToCheck == previousBelow)
                    {
                        possibleBlobbs.RemoveAt(k);
                    }
                }
                //instantiate in position
                Vector3    pos         = new Vector3(transform.position.x + i, transform.position.y + j, 0);
                int        randomindex = Random.Range(0, possibleBlobbs.Count);
                GameObject newBlobb    = Instantiate(possibleBlobbs[randomindex], pos, transform.rotation);
                //set parent this obj
                newBlobb.transform.SetParent(this.transform);
                //add to list
                Blobb b = newBlobb.GetComponent <Blobb>();
                allBlobs.Add(b);

                //save id
                previousBelow   = b.id;
                previousLeft[j] = b.id;
            }
        }
    }