示例#1
0
 // return true if any geometry is rotating
 bool IsRotating()
 {
     foreach (GameObject go in geos)
     {
         GeoBehavior geo = go.GetComponent <GeoBehavior> ();
         if (geo.rotating)
         {
             return(true);
         }
     }
     return(false);
 }
示例#2
0
    public void Clicked()
    {
        RaycastHit hit;

        // if geo not rotating and a cube get clicked
        if (!IsRotating() && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
        {
            // get cube
            GameObject clickedCube = hit.collider.gameObject;

            if (clickedCube != null)
            {
                // make sure the object get clicked is a cube
                var cp = clickedCube.transform.parent.gameObject.GetComponent <CubeProp> ();

                if (cp != null)
                {
                    // make clicked cube the ball's new cubeAttachment
                    cubeAttachment = clickedCube.transform.parent.gameObject;

                    // update geo canRotate
                    GeoBehavior ballGeo = cp.controller;
                    ballGeo.canRotate = true;
                    foreach (GameObject go in geos)
                    {
                        if (ballGeo.gameObject != go)
                        {
                            GeoBehavior otherGeo = go.GetComponent <GeoBehavior> ();
                            otherGeo.canRotate = false;
                            print(otherGeo + "false");
                        }
                    }

                    // make sure every translation takes the same time
                    speed = Vector3.Distance(transform.position, cubeAttachment.transform.position) / time;
                }
            }
        }
    }
示例#3
0
    void InitialEmpties()
    {
        // get geo mesh
        mesh = GetComponent <MeshFilter> ().mesh;

        //get geo
        GeoBehavior geo = GetComponent <GeoBehavior> ();

        // initialize empties
        empties = new GameObject[mesh.vertices.Length];

        // create empty game objects to keep track of all vertices
        for (int i = 0; i < mesh.vertices.Length; i++)
        {
            Vector3    vertice = transform.TransformPoint(mesh.vertices [i]);
            GameObject emptyOb = new GameObject();
            emptyOb.transform.position = vertice;
            emptyOb.transform.parent   = transform;
            CubeProp cp = emptyOb.AddComponent <CubeProp> ();
            cp.controller = geo;
            empties [i]   = emptyOb;
        }
    }