bool CreateArmor(int x, int y) { if (map.GetBlock(x, y) != null) { return(false); } Block[] blocks = new Block[4]; blocks[0] = map.GetBlock(x - 1, y); blocks[1] = map.GetBlock(x + 1, y); blocks[2] = map.GetBlock(x, y - 1); blocks[3] = map.GetBlock(x, y + 1); if (blocks[0] == null && blocks[1] == null && blocks[2] == null && blocks[3] == null) { return(false); } Vector3 pos = transform.TransformPoint(new Vector3(x, y, 0.0f)); GameObject tobj = (GameObject)Instantiate(ArmorPrefab, pos, GetComponent <Rigidbody2D>().transform.rotation); tobj.transform.parent = transform; GameObject NewArmor = (GameObject)tobj; Armor armor = NewArmor.GetComponent <Armor>(); bool createsuccess = map.AddBlock(x, y, armor); if (!createsuccess) { throw null; } /* * foreach (Block block in blocks) * { * if (block == null) * continue; * * float mx = block.transform.position.x + pos.x; mx /= 2; * float my = block.transform.position.y + pos.y; my /= 2; * float mz = block.transform.position.z + pos.z; mz /= 2; * * * * * GameObject NewEdge = (GameObject)Instantiate(EdgePrefab, new Vector3(mx, my, mz), quat); * * var armorscript = NewArmor.GetComponent<Armor>(); * var edgeblocks = NewEdge.GetComponent<Edge>(); * NewEdge.GetComponent<Edge>().AddBlock(block); * NewEdge.GetComponent<Edge>().AddBlock(NewArmor.GetComponent<Armor>()); * HingeJoint2D[] hinges = NewEdge.GetComponents<HingeJoint2D>(); * Debug.Log(hinges.ToString()); * //hinges[1].connectedBody = NewArmor.GetComponent<Rigidbody2D>(); * //hinges[0].connectedBody = block.GetComponent<Rigidbody2D>(); * //Debug.Log (hinges[1].connectedBody.ToString()); * * map.Rebuild(this); * Debug.Log(map.BlockCount); * //edgehinge. * * } */ return(true); }