public void setBlockGrabbed(Rigidbody b) { JengaBlock jb = b.gameObject.GetComponent <JengaBlock>(); int bColor = 5; if (jb != null) { bColor = jb.color; } if ((bColor != tColor) || ((lastBlockGrabbed != null) && (lastBlockGrabbed != b))) { Debug.Log("Wrong block"); if (animator != null) { animator.SetTrigger("Wrong Block Grabbed"); } } else { lastBlockGrabbed = b; } blockGrabbed = true; }
public JengaBlockData(JengaBlock b) { id = b.id; p = new float[] { b.p.x, b.p.y, b.p.z }; r = new float[] { b.r.x, b.r.y, b.r.z, b.r.w }; e = b.e; }
private static void HighlightSelectedBlock() { RaycastHit hit; if (Input.GetMouseButton(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider.tag == "JengaBlock") { JengaBlock jengaBlock = hit.collider.GetComponent <JengaBlock>(); jengaBlock.SetSelected(); jengaBlock.GetComponent <Renderer>().material.color = Color.blue; jengaBlock.Move(); } } } }
private int Simulate() { var blocks = new List <JengaBlock>(); var numBlocks = 0; var blockLength = 1; var firstBlock = new JengaBlock(++numBlocks, 0, blockLength); blocks.Add(firstBlock); while (blocks.All(b => b.IsStable())) { var topBlock = blocks.Last(); var newBlockCenter = topBlock.MinX + (topBlock.MaxX - topBlock.MinX) * this._randomNumberGenerator.NextDouble(); var newBlock = new JengaBlock(++numBlocks, newBlockCenter, blockLength); foreach (var block in blocks) { block.AddBlock(newBlockCenter); } blocks.Add(newBlock); } return(blocks.Count); }
public void blockTouchesGround(Rigidbody b) { if (lastBlockGrabbed == null) { return; } JengaBlock jb = b.GetComponent <JengaBlock>(); if (jb == null) { return; } if (jb.floor == 0) { return; } if (b != lastBlockGrabbed) { Debug.Log(gameObject.name + ": Wrong block falls"); if (animator != null) { animator.SetTrigger("Wrong Block Falls"); } } else { blockFalls(); if (animator != null) { animator.SetTrigger("Block Falls"); } } }