public void AddPlaceableObject(Waypoint waypoint) { if (placeableObject == null) { return; } if (!waypoint.isPlaceable) { return; } if (placeableObject.GetCost() > score.GetTotalScore()) { SetActivePlaceableObject(null); Debug.Log("Not enough points!"); return; } if (placeableObject.GetComponent <Blocker>() && objectManager.blockers.Count >= objectManager.maxBlockers) { Debug.Log("Can't add more blockers"); return; } if (placeableObject.canSpawnOnRoads && !waypoint.isRoad) { Debug.Log(placeableObject.name + ": Can't place here: " + waypoint.name); return; } else if (!placeableObject.canSpawnOnRoads && waypoint.isRoad) { Debug.Log(placeableObject.name + ": Can't place here: " + waypoint.name); return; } else if (placeableObject.canSpawnOnRoads && waypoint.isRoad) { FindObjectOfType <Score>().DecreasePoints(placeableObject.GetCost()); InstantiateNewObject(waypoint); return; } else { FindObjectOfType <Score>().DecreasePoints(placeableObject.GetCost()); InstantiateNewObject(waypoint); if (hoverPlaceableObject != null) { Destroy(hoverPlaceableObject.gameObject); hoverPlaceableObject = null; } } }
private void Update() { if (LevelManager.Instance.GetState() == State.Game) { if (placeableObjectPrefab.GetComponent <Blocker>() && objectManager.blockers.Count >= objectManager.maxBlockers) { isActive = false; DisableButton(); return; } if (mouseOver && isEnabled && Input.GetMouseButtonUp(0)) { GetComponentInParent <GameUIHandler>().SetActiveButton(this); } if (isEnabled) { overlay.SetActive(false); } if (isActive) { GetComponent <Image>().color = Color.red; } if (!isActive) { GetComponent <Image>().color = Color.white; } if (placeableObjectPrefab.GetCost() > score.GetTotalScore()) { DisableButton(); } if (placeableObjectPrefab.GetCost() < score.GetTotalScore()) { EnableButton(); } if (LevelManager.Instance.isInBulldozeMode) { DisableButton(); } } }