示例#1
0
    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);
    }
示例#2
0
    private void Start()
    {
        player = NetworkClient.connection.identity.GetComponent <RTSPlayer>();

        ClientHandleResourcesUpdated(player.GetResources());
        player.ClientOnResourcesUpdated += ClientHandleResourcesUpdated;
    }
示例#3
0
    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
    }
示例#5
0
 private void Update()
 {
     timer -= Time.deltaTime;
     if (timer <= 0)
     {
         player.SetResources(player.GetResources() + resoucesPerInterval);
         timer += interval;
     }
 }
示例#6
0
    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);
    }
示例#7
0
    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;
            }
        }
    }
示例#9
0
    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;
            }
        }
    }
示例#10
0
    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;
        }
    }
示例#11
0
    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>();
    }
示例#12
0
    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);
    }
示例#13
0
    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);
    }
示例#14
0
    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);
    }
示例#15
0
    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();
    }
示例#16
0
    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;
    }