public GameObject GenCardWithProperties(string colorS, string shapeS, int count, int xpos, int ypos, bool sel) { var mat = matsDB.GetMaterial(colorS); var shape = shapesDB.GetPrefab(shapeS); var cardBase = cardBases[count - 1]; cardBase = Instantiate(cardBase); var gemLocs = cardBase.GetComponentsInChildren <Transform>(); foreach (var loc in gemLocs) { if (loc.gameObject.tag == "Card") { continue; } var g = Instantiate(shape, loc.position, Quaternion.identity); if (shape.name == "Triangle") { g.transform.Rotate(new Vector3(180f, 0f, 0f)); } try { g.GetComponent <Renderer>().material = mat; } catch { g.GetComponentInChildren <Renderer>().material = mat; } g.transform.parent = loc; } var properties = cardBase.GetComponent <CardProperties>(); properties.count = gemLocs.Length - 1; properties.color = mat; properties.shape = shape; cardBase.transform.Rotate(new Vector3(0f, 150f, 0f)); // Gets the hex cell specified by the x/y coordinates, then sets the transform position to that cell's transform position cardBase.transform.position = hexgrid.GetCell(xpos, ypos).transform.localPosition; return(cardBase); }