Example #1
0
 void MakeBuddies(StoneController stone1, StoneController stone2, StoneController stone3)
 {
     stone1.AddNeighbor(stone2);
     stone1.AddNeighbor(stone3);
     stone2.AddNeighbor(stone1);
     stone2.AddNeighbor(stone3);
     stone3.AddNeighbor(stone1);
     stone3.AddNeighbor(stone2);
 }
Example #2
0
    void Start()
    {
        mesh = GetComponentInChildren <MeshFilter>();

        IndexPairs[] edges   = GetEdges();
        float        closest = 1;

        foreach (IndexPairs pair in edges)
        {
            Vector3 a = mesh.mesh.vertices[pair.a];
            Vector3 b = mesh.mesh.vertices[pair.b];
            float   d = (a - b).sqrMagnitude;
            if (d < closest)
            {
                closest = d;
            }
        }
        float separation = minimumSeparation / Mathf.Sqrt(closest);

        mesh.transform.localScale = Vector3.one * separation;

        StoneController[] stones = new StoneController[mesh.mesh.vertices.Length];
        for (int i = 0; i < mesh.mesh.vertices.Length; i++)
        {
            Vector3         v     = mesh.mesh.vertices[i] * separation;
            Quaternion      rot   = Quaternion.FromToRotation(Vector3.up, mesh.mesh.normals[i]);
            StoneController stone = Instantiate(stonePrefab, v, rot, transform);
            stone.SetGameState(0);
            stones[i] = stone;
        }

        foreach (IndexPairs pair in edges)
        {
            StoneController a = stones[pair.a];
            StoneController b = stones[pair.b];
            a.AddNeighbor(b);
            b.AddNeighbor(a);
        }
    }