private void PlaceUnit() { if (this.clickedButton == null) { return; } if (clickedButton.UnitPrefab == null) { //This means EditButton is selected RaycastHit hitData; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hitData)) { if (hitData.transform.tag == "Player") { editMenu.LoadUnit(hitData.transform.GetComponent <Unit>()); } } } else if (!EventSystem.current.IsPointerOverGameObject() && this.partyCount < this.partyLimit) { this.clickedButton.unitCount += 1; GameObject unitObj = (GameObject)Instantiate(this.clickedButton.UnitPrefab, transform.position, Quaternion.identity); Unit unit = unitObj.GetComponent <Unit>(); if (unit != null) { unit.number.text = (this.partyCount + 1).ToString(); unit.enabled = false; } Vector3 mousePos = Input.mousePosition; Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos); worldPos.z = 1; unitObj.transform.position = worldPos; unitList.Add(unit); unitEntries.Add(new UnitEntry() { unitID = this.clickedButton.unitID, unitScript = unit, unitPos = unit.transform.position }); this.partyCount += 1; } }