public void PlaceObject(GameObject jengaBlock)
        {
            List <Vector3> placesToConsider = GetPlacesToConsider();
            var            lowest           = placesToConsider.Aggregate((agg, next) =>
            {
                if (agg.y < next.y)
                {
                    return(agg);
                }
                return(next);
            });

            jengaBlock.transform.position = lowest;
            JengaTowerUtils.SetProperRotation(jengaBlock);
            JengaTowerUtils.SetProperPosition(jengaBlock);
        }
Esempio n. 2
0
        private void UpdateStateSelected()
        {
            blockPicked = true;
            if (Input.GetKeyDown(KeyCode.Q))
            {
                selected.collider.gameObject.renderer.materials[0].color = oldColor;
                SwitchState(State.ToSelect);
                return;
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                selected.transform.Rotate(Vector3.up, 90.0f);
            }


            JengaTowerUtils.SetProperRotation(selected);


            if (Input.GetMouseButtonDown(0))
            {
                FinishSelection();

                return;
                //copySelected.SetActive(false);
                // copySelected.rigidbody.detectCollisions = false;
            }
            selected.rigidbody.isKinematic = true;
            //SetProperRotation();

            RayCast(hit =>
            {
                Vector3 newPosition         = hit.point;
                Vector2 d2NewAvailiblePos   = FindCLosestAvailiblePos(new Vector2(newPosition.x, newPosition.z));
                selected.transform.position =
                    JengaTowerUtils.FindHighestFreeAtPosition(new Vector3(d2NewAvailiblePos.x, 0, d2NewAvailiblePos.y));

                selected.collider.gameObject.renderer.materials[0].color = oldColor;
                JengaTowerUtils.SetProperPosition(selected);
                //Destroy(copySelected);
                //SwitchState(State.ToSelect);
            });
        }