private List <Vector3> GetPlacesToConsider() { jengaBlocks = GameObject.Find("Jenga_Blocks_Controller").GetComponent <Jenga_SetUpBlocks>().blockList; jengaTower = new JengaTower(jengaBlocks); List <Vector2> pointsAvailibleForPlacing = GameObject.Find("Jenga_Blocks_Controller").GetComponent <Jenga_Controller>().pointsAvailibleForPlacing; var result = pointsAvailibleForPlacing.Select( x => JengaTowerUtils.FindHighestFreeAtPosition(new Vector3(x.x, 0, x.y))).ToList(); return(result); }
private static void PlacePrimitiveTop(GameObject jengaBlock) { var jengaStartPosition = Vector3.zero; //magic number just like SOMEONE did in jenga tower creation Vector3 highestFreeAtPosition = JengaTowerUtils.FindHighestFreeAtPosition(jengaStartPosition); highestFreeAtPosition.x += 1; jengaBlock.transform.rotation = new Quaternion(); if (((int)(highestFreeAtPosition.y / 1.5f)) % 2 == 0) { jengaBlock.transform.Rotate(new Vector3(0, 90, 0)); } jengaBlock.transform.position = highestFreeAtPosition; }
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); }
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); }); }