Пример #1
0
    /// <summary>
    /// If your mouse is being right clicked over an ant you don't own and you have a beatle unit selected, check the range to see if it is less than BEATLE_RANGE, if it is less, stop the Navigation and fire projectile.
    /// </summary>
    void OnMouseOver()
    { // For Beatle Ranged Attacks
      // setup Timer for atk Spd


        if (Input.GetMouseButtonDown(1))
        {
            if (!hasAuthority)
            {     // if it is not owned by you
                if (WorldHandler.isBeatleUnitSelected())
                { // for beatle ranged units
                    ArrayList beatles = WorldHandler.getBeatleUnitsAsArray();
                    foreach (GameObject beatle in beatles)
                    {
                        float range = beatle.GetComponent <Beatle>().Range;
                        Debug.Log("Beatle Range: " + range);
                        Debug.Log("Distance from ant and the beatle: " + Vector3.Distance(transform.position, beatle.transform.position));
                        if (Vector3.Distance(transform.position, beatle.transform.position) <= range)
                        {
                            WorldHandler localPlayer = WorldHandler.findLocalPlayer().GetComponent <WorldHandler>();
                            localPlayer.Cmd_FireProjectile(beatle, transform.position);
                        }
                    }
                } // end beatle ranged units
            }
        }
    }
Пример #2
0
    void Update()
    {
        // Time does not start until Time.timeScale has been set to 1.
        gameTime += Time.deltaTime;
        minutes   = Mathf.FloorToInt(gameTime / 60F);
        seconds   = Mathf.FloorToInt(gameTime - minutes * 60);
        timeFixed = string.Format("{0:0}:{1:00}", minutes, seconds);
        // End time

        timer += Time.deltaTime;
        if (timer >= timerMax)
        {
            if (isLocalPlayer)
            {
                UpdateResources();

                timer = 0;
            }
        }

        if (!WorldHandler.isBeatleUnitSelected() && !WorldHandler.isAntUnitSelected() && !WorldHandler.isAntHillSelected())
        {
            hideUnitInfo();
            anthillInfo.SetActive(false);
        }



        if (Input.GetKeyDown(KeyCode.Escape))            // if the Escape key is pressed, unconfine the cursor from its state set in the Start() function
        {
            Cursor.lockState = CursorLockMode.None;
            // Open Exit Menu
            isExitMenuOpen = !isExitMenuOpen;
            EscapeMenu.SetActive(isExitMenuOpen);
        }

        updateHUD();


        if (!isLocalPlayer)
        {
            return;
        }


        if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter) && EventSystem.current.currentSelectedGameObject.name == "EnterMessage")
        {
            InputField theInputField = inputField.GetComponent <InputField> ();


            if (!string.IsNullOrEmpty(theInputField.text))
            {
                string txtToSend = theInputField.text;



                if (txtToSend == "cls")
                {
                    scrollText.GetComponent <Text> ().text = "";
                }

                if (GetComponent <UnitIdentity> ().id == 0)
                {
                    Cmd_SendMessageToAllClients("<color=#ff0000ff>Player " + GetComponent <UnitIdentity>().id + "</color>: " + txtToSend);
                }
                if (GetComponent <UnitIdentity> ().id == 1)
                {
                    Cmd_SendMessageToAllClients("<color=#0000ffff>Player " + GetComponent <UnitIdentity>().id + "</color>: " + txtToSend);
                }

                theInputField.text = "";
            }
        }


        if (inputField.GetComponent <InputField> ().isFocused)
        {
            Camera.main.GetComponent <CameraController> ().enabled = false;
        }
        else
        {
            Camera.main.GetComponent <CameraController> ().enabled = true;
        }

        // Update FPS Counter

        if (Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl))
        {
            if (Input.GetKeyDown(KeyCode.F))
            {
                displayFrameRate = !displayFrameRate;
            }
        }

        if (displayFrameRate)
        {
            if (float.IsInfinity(FPS))
            {
                fpsText.text = "Game is paused.";
            }
            else
            {
                // Round FPS
                FPS          = Mathf.RoundToInt(FPS);
                fpsText.text = "FPS: " + FPS;
            }
        }
        else
        {
            fpsText.text = "";
        }

        deltaTime += Time.deltaTime;
        deltaTime /= 2.0f;
        FPS        = 1.0f / deltaTime;
        // End Update FPS Counter
        // Sync timer and resource gathering
    }