// If crown exists in word, places connected crown bonus object onto random tile protected override void popCrown(WordTile from, Tile to) { GameObject g = from.getCrown(); // Find the crown within the word RectTransform rt = g.GetComponent <RectTransform>(); // Find the location of the crown Vector3 offset = g.GetComponent <RectTransform>().anchoredPosition3D; // extract the coordinates of the crown offset.x = offset.x * g.GetComponent <RectTransform>().localScale.x; // extract x coordinate of crown offset.y = offset.y * g.GetComponent <RectTransform>().localScale.y; // extract y coordinate of crown offset.z = offset.z * g.GetComponent <RectTransform>().localScale.z; // extract z coordinate of crown g.transform.SetParent(this.transform); // Set crown position to be relative to whole grid, instead of current location g.SetActive(true); // activate the crown bonus object g.transform.SetAsLastSibling(); // move the crown to bottom of priority list Vector3 pos = to.GetComponent <RectTransform>().anchoredPosition3D + offset; // find the position to which crown will be moved base.popCrown(from, to); // remove crown fro current position rt.DOAnchorPos3D(pos, 0.5f).SetEase(Ease.InQuart).OnStepComplete(() => { // gradually animate crown in new position g.SetActive(false); // inactivate crown object }); }