Exemple #1
0
    /// <summary>
    /// This method sends out raycasts that look for collisions with the stone's colliders.
    /// </summary>
    private void MeshUpdate(Ray ray)
    {
        RaycastHit hit;

        Debug.DrawRay(ray.origin, ray.direction * 10);

        if (Physics.Raycast(ray, out hit, float.PositiveInfinity))
        {
            StoneController stone = hit.collider.GetComponent <StoneController>();
            if (stone.value == 0)
            {
                if (Input.GetButtonDown("Fire1"))
                {
                    stone.SetGameState(1);
                }
            }
        }
    }
Exemple #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);
        }
    }