private void UpdateShootPointNBarrelObj() { //get shootpoint, assigned to TurretObject component on turretObject if (turretObject != null) { TurretObject turretObj = turretObject.gameObject.GetComponent <TurretObject>(); if (turretObj != null) { barrelObject = turretObj.barrelPivotPoint; //make sure the shootpoint is not null if (turretObj.shootPoint != null && turretObj.shootPoint.Length > 0) { shootPoint = turretObj.shootPoint; return; } } else { barrelObject = null; //no specify shootpoint, use turretObject itself shootPoint = new Transform[1]; shootPoint[0] = turretObject; return; } } //this tower have no turretObject, use thisT as shootPoint shootPoint = new Transform[1]; shootPoint[0] = unit.thisT; return; }
public void SelectTurret(GameObject turretGO, ShopButtonUI button) { if (turretGO == selectedTurret) { selectedButtonUI.Deselect(); selectedTurret = null; button = null; return; } // 1) disselect turret if (selectedButtonUI != null) { selectedButtonUI.Deselect(); } // 2) = selectedTurret = turretGO; selectedButtonUI = button; // select Turret turret = selectedTurret.GetComponent <Turret>(); SetTurretData(turret?.CurrentTurret); selectedButtonUI.Select(); void SetTurretData(TurretObject data) => turretData = data; }
public void UpgradeTurret() { if (level == TurretLevels.Length) { BuildManager.singleton.TurretMaxLevelalert(gameObject.GetComponentInParent <Transform>()); return; } if (BuildManager.singleton.TryUpgradeTurret(gameObject.GetComponentInParent <Platform>())) { CurrentTurret = TurretLevels[level++]; UpdateData(); } }
public void Init(TurretObject t) { turretPrefab = t.TurretPrefab; selectedSprite = t.selectedTurretUI; deselectedSprite = t.deselectedTurretUI; cost.text = "₴" + t.cost.ToString(); image.sprite = deselectedSprite; Shop shop = transform.parent.GetComponent <Shop>(); Button turretButton = GetComponent <Button>(); turretButton.onClick.AddListener(() => shop.TurretPressed(turretPrefab, this)); turretButton.GetComponent <RectTransform>().localScale = Vector3.one; }