public void onBeginDrag(PointerEventData eventData) { Debug.Log($"Begin Drag"); if (player.GetResources() < building.GetPrice()) { return; } buildingPreviewInstance = Instantiate(building.GetBuildingPreview()); buildingRendererInstance = buildingPreviewInstance.GetComponentInChildren <Renderer>(); buildingPreviewInstance.SetActive(false); }
private void Start() { player = NetworkClient.connection.identity.GetComponent <RTSPlayer>(); ClientHandleResourcesUpdated(player.GetResources()); player.ClientOnResourcesUpdated += ClientHandleResourcesUpdated; }
private void CmdSpawnUnit() { if (queuedUnits == maxUnitQueue) { return; } RTSPlayer player = connectionToClient.identity.GetComponent <RTSPlayer>(); if (player.GetResources() < unitPrefab.GetResourceCost()) { return; } queuedUnits++; player.SetResources(player.GetResources() - unitPrefab.GetResourceCost()); }
private void Start() { player = NetworkClient.connection.identity.GetComponent <RTSPlayer>(); ClientHandleResourcesUpdated(player.GetResources()); // first update the UI player.ClientOnResourcesUpdated += ClientHandleResourcesUpdated; // then update with further resoruce updates }
private void Update() { timer -= Time.deltaTime; if (timer <= 0) { player.SetResources(player.GetResources() + resoucesPerInterval); timer += interval; } }
private void Resources(int olda, int newa) { Debug.Log($"connectionToClient {connectionToClient}"); if (queuedUnits == maxUnitQueue) { return; } //RTSPlayer player = connectionToClient.identity.GetComponent<RTSPlayer>(); RTSPlayer player = NetworkClient.connection.identity.GetComponent <RTSPlayer>(); Button btn = this.gameObject.GetComponent <Button>(); // if (player.GetResources() > ResourcesNeeded) { btn.interactable = true; ; } //Debug.Log(false); queuedUnits++; //hook interactableTrue if (player.GetResources() < ResourcesNeeded) { return; } player.SetResources(player.GetResources() - ResourcesNeeded); }
private void Update() { if (player == null) { // todo: this causes a known error which will be addressed in a later lesson player = NetworkClient.connection.identity.GetComponent <RTSPlayer>(); if (player != null) { ClientHandleResourcesUpdated(player.GetResources()); player.ClientOnResourcesChanged += ClientHandleResourcesUpdated; } } }
private void Update() { if (player == null) { player = NetworkClient.connection.identity.GetComponent <RTSPlayer>(); if (player != null) { ClientHandleResourcesUpdated(player.GetResources()); player.ClientOnResourcesUpdated += ClientHandleResourcesUpdated; } } }
private void Update() { if (player == null) { //This set player on Update. Only sets it until not null player = NetworkClient.connection.identity.GetComponent <RTSPlayer>(); //Get the identity component of the client connection calling this script. This allows us to get RTSPlayer component //Once player is found Update UI & subscribe to future Server ResourceUpdates if (player != null) { ClientHandleResourcesUpdated(player.GetResources()); player.ClientOnResourcesUpdated += ClientHandleResourcesUpdated; } } }
private void Update() { //Subtract amount of seconds passed from interval amount. resourceTimer -= Time.deltaTime; //If below Generate resources & reset timer. if (resourceTimer <= 0) { //Generate resources for player player.SetResources(player.GetResources() + resourcePerInterval); //Reset to,er resourceTimer += interval; } }
public void OnPointerDown(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } if (player.GetResources() < building.GetPrice()) { return; } buildingPreviewInstance = Instantiate(building.GetBuildingPreview()); buildingPreviewInstance.SetActive(false); buildingRendererInstance = buildingPreviewInstance.GetComponentInChildren <Renderer>(); }
private void interactableTrue(int oldUnits, int newUnits) { RTSPlayer player = NetworkClient.connection.identity.GetComponent <RTSPlayer>(); //Debug.Log(9); remainingUnitsText.text = newUnits.ToString(); //print the number Button btn = this.gameObject.GetComponent <Button>(); if (player.GetResources() < ResourcesNeeded) { btn.interactable = false;; } //botton can touch now // Debug.Log(queuedUnits); }
public void OnPointerDown(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } if (player.GetResources() < building.GetPrice()) { return; } //Instantiate preview building & get renderer buildingPreviewInstance = Instantiate(building.GetBuildingPreview()); buildingRendererInstance = buildingPreviewInstance.GetComponentInChildren <Renderer>(); //Set the preview instance active to false. Keeps building from displaying until mouse position is valid buildingPreviewInstance.SetActive(false); }
public void OnPointerDown(PointerEventData eventData) { // we are waiting on the left button, thanks if (eventData.button != PointerEventData.InputButton.Left) { return; } // no enough money if (player.GetResources() < building.GetPrice()) { return; } buildingPreviewInstance = Instantiate(building.GetBuildingPreview()); buildingRendererInstance = buildingPreviewInstance.GetComponentInChildren <Renderer>(); buildingPreviewInstance.SetActive(false); }
public void OnPointerDown(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } if (player.GetResources() < building.GetPrice()) { animator.SetTrigger("NotEnoughResourcesTrigger"); return; } unitSelectionHandler.gameObject.SetActive(false); buildingPreviewInstance = Instantiate(building.GetBuildingPreview()); buildingRendererInstance = buildingPreviewInstance.GetComponentInChildren <Renderer>(); buildingPreviewInstance.SetActive(false); player.ShowLegalBuildingPlacement(); }
private void unitTimers() { Button btn = this.gameObject.GetComponent <Button>(); RTSPlayer player = NetworkClient.connection.identity.GetComponent <RTSPlayer>(); if (queuedUnits == 0) { return; } unitTimer += Time.deltaTime; if (player.GetResources() < ResourcesNeeded) { GameObject[] cards = GameObject.FindGameObjectsWithTag("Card"); foreach (GameObject card in cards) { card.GetComponent <Button>().interactable = false; Debug.Log(9); } } if (player.GetResources() < ResourcesNeeded) { Debug.Log(8); } else { if (unitTimer > 5) { btn.interactable = true; } } if (btn.interactable == false) { return; } if (player.GetResources() > ResourcesNeeded) { GameObject[] cards = GameObject.FindGameObjectsWithTag("Card"); foreach (GameObject card in cards) { card.GetComponent <Button>().interactable = true;; } } if (unitTimer > 5) { btn.interactable = true; } if (unitTimer < unitSpawnDuration) { return; } // Debug.Log($"2 Produce Unit unitSpawnDuration {unitSpawnDuration} , unitTimer {unitTimer}"); queuedUnits--; unitTimer = 0f; Screen.orientation = ScreenOrientation.Portrait; float newProgress = unitTimer / unitSpawnDuration; }