예제 #1
0
        public void SwitchTab(string newTabName)
        {
            if (!gameManager.GameHasStarted())
            {
                return;
            }

            GameObject newPanel   = (newTabName == economyPanel.name ? economyPanel : newTabName == carbonPanel.name ? carbonPanel : null);
            GameObject otherPanel = newPanel.Equals(economyPanel) ? carbonPanel : economyPanel;

            if (newPanel != null && otherPanel != null)
            {
                ToggleButtons(newPanel, true);
                ToggleButtons(otherPanel, false);
            }
        }
예제 #2
0
        // Update is called once per frame
        void Update()
        {
            if (!gameManager.GameHasStarted())
            {
                return;
            }

            Vector3 mousePos = Input.mousePosition;

            if (hovering && Input.GetMouseButtonDown(0))
            {
                resource         = SpawnResource();
                resourceRenderer = resource.GetComponent <Renderer>();
                SetResourceAlpha(blueprintAlpha);
                dragging = true;
            }

            if (resource != null && Input.GetMouseButton(0))
            {
                Vector3    dir = new Vector3(mousePos.x, 0, mousePos.y);
                RaycastHit hit;
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
                {
                    resource.transform.position = new Vector3(Mathf.Round(hit.point.x / gridLockSize) * gridLockSize + positionOffset.x, positionOffset.y, Mathf.Round(hit.point.z / gridLockSize) * gridLockSize + positionOffset.z);
                }
            }

            if (!hovering && Input.GetMouseButtonUp(0) && resource != null)
            {
                if (!gameManager.HasSufficientFundsToPlace(resourceName))
                {
                    Destroy(resource);
                }
                else
                {
                    gameManager.AddEnergyResource(resourceName);
                    SetResourceAlpha(1.0f);
                    dragging = false;
                    resource = null;
                }
            }
        }
예제 #3
0
 void Update()
 {
     if (gameManager == null)
     {
         GameObject gObject = GameObject.FindGameObjectWithTag("GameManager");
         if (gObject != null)
         {
             gameManager = gObject.GetComponent <GameManager>();
         }
     }
     else if (!placementScript.IsDragging() && gameManager.GameHasStarted())
     {
         if (Input.GetMouseButton(0))
         {
             if (transform.rotation.y % 180 == 0)
             {
                 int sf = transform.rotation.y == 0 ? -1 : 1;
                 velocity.x = sf * Input.GetAxis("Mouse X") * speed * Time.deltaTime;
                 velocity.z = sf * Input.GetAxis("Mouse Y") * speed * Time.deltaTime;
             }
             else
             {
                 int sf = transform.rotation.y == 0 ? -1 : 1;
                 velocity.z = Input.GetAxis("Mouse Y") * speed * Time.deltaTime;
                 velocity.x = Input.GetAxis("Mouse X") * speed * Time.deltaTime;
             }
         }
         else
         {
             velocity.x = Mathf.Clamp(velocity.x, -maxSpeed, maxSpeed);
             velocity.z = Mathf.Clamp(velocity.z, -maxSpeed, maxSpeed);
             velocity   = (velocity.magnitude > 1) ? velocity - (velocity.normalized * acceleration) : velocity = Vector3.zero;
         }
         transform.position += velocity;
         transform.position  = new Vector3(Mathf.Clamp(transform.position.x, xMin, xMax), transform.position.y, Mathf.Clamp(transform.position.z, yMin, yMax));
     }
 }