Exemplo n.º 1
0
    void listenAndCastMeteor()
    {
        Vector3 rayEndPos = meteorRaycastLine.GetComponent <LineRenderer>().GetPosition(1);

        if (SteamVR_Input.GetBooleanAction("CastMeteor").GetStateDown(SteamVR_Input_Sources.LeftHand))
        {
            Debug.Log("pressed down");
            isCastingMeteor = true;
            meteorRaycastLine.GetComponent <LineRenderer>().enabled = true;
        }
        if (isCastingMeteor)
        {
            Vector3 endPos = meteorRaycastLine.GetComponent <LineRenderer>().GetPosition(1);
            //half way along the ray?
            Vector3 controlPos = leftHandRay.GetPoint(100.0f / 2);
            endPos.y      = 0.0f;
            controlPos.y += 25.0f;
            renderBezierCurve(leftHandRay.origin, endPos, controlPos);
            // Set the flag, so the moment the trigger isn't held we can teleport
            rayEndPos = endPos;
        }
        if (SteamVR_Input.GetBooleanAction("CastMeteor").GetStateUp(SteamVR_Input_Sources.LeftHand))
        {
            Debug.Log("released");
            blueCastle.GetComponent <BlueCastle>().UseMeteor(rayEndPos, blueCastle.GetComponent <BlueCastle>().getForce());
            isCastingMeteor = false;
            meteorRaycastLine.GetComponent <LineRenderer>().enabled = false;
        }
    }
Exemplo n.º 2
0
        private void Awake()
        {
            toggleLaserPointer = SteamVR_Input.GetBooleanAction("ToggleLaserPointer");

            CreatePointerObjects();
            ItemEquippableEvents.OnPlayerWieldItem += PlayerChangedItem;
            VRConfig.configUseLaserPointerOnWeapons.SettingChanged += LaserPointerToggled;
            VRConfig.configLaserPointerColor.SettingChanged        += LaserPointerColorChanged;
        }
Exemplo n.º 3
0
        public void Setup(Transform parent)
        {
            m_radialItems    = new Dictionary <InventorySlot, RadialItem>();
            m_retrievedIcons = new Dictionary <InventorySlot, Sprite>();

            hackyInput[InputAction.SelectMelee]        = false;
            hackyInput[InputAction.SelectConsumable]   = false;
            hackyInput[InputAction.SelectHackingTool]  = false;
            hackyInput[InputAction.SelectResourcePack] = false;
            hackyInput[InputAction.SelectStandard]     = false;
            hackyInput[InputAction.SelectSpecial]      = false;
            hackyInput[InputAction.SelectTool]         = false;

            m_weaponRadialAction = SteamVR_Input.GetBooleanAction("WeaponRadialMenu");

            m_radialMenu = new GameObject("WeaponRadial").AddComponent <RadialMenu>();
            m_radialMenu.Setup(VR_Input.InteractionHand.MainHand);
            m_radialMenu.transform.SetParent(parent);

            m_radialMenu.AddRadialItem("Melee", WantToSelectMelee, out RadialItem melee);
            m_radialMenu.AddRadialItem("Secondary", WantToSelectSecondary, out RadialItem secondary);
            m_radialMenu.AddRadialItem("Tool", WantToSelectTool, out RadialItem tool);
            m_radialMenu.AddRadialItem("Pack", WantToSelectPack, out RadialItem pack);
            m_radialMenu.AddRadialItem("HackingTool", WantToSelectHackingTool, out RadialItem hackingTool);
            m_radialMenu.AddRadialItem("Consumable", WantToSelectConsumable, out RadialItem consumable);
            m_radialMenu.AddRadialItem("Primary", WantToSelectPrimary, out RadialItem primary);
            m_radialMenu.OnMenuClosedWithoutItem += MenuClosedQuick;

            melee.SetIcon(VRAssets.MeleeFallback, 1.5f);
            primary.SetIcon(VRAssets.PrimaryFallback);
            secondary.SetIcon(VRAssets.SecondaryFallback);
            tool.SetIcon(VRAssets.ToolFallback);
            consumable.SetIcon(VRAssets.ThrowableFallback);
            pack.SetIcon(VRAssets.PackFallback);
            hackingTool.SetIcon(VRAssets.HackingToolFallback);

            pack.Active       = false;
            consumable.Active = false;

            m_radialItems.Add(InventorySlot.GearMelee, melee);
            m_radialItems.Add(InventorySlot.GearStandard, primary);
            m_radialItems.Add(InventorySlot.GearSpecial, secondary);
            m_radialItems.Add(InventorySlot.GearClass, tool);
            m_radialItems.Add(InventorySlot.Consumable, consumable);
            m_radialItems.Add(InventorySlot.ResourcePack, pack);
            m_radialItems.Add(InventorySlot.HackingTool, hackingTool);

            InventoryAmmoEvents.OnInventoryAmmoUpdate    += AmmoUpdate;
            BackpackEvents.OnNewItemStatus               += ItemStatusChanged;
            VRConfig.configWeaponInfoText.SettingChanged += ToggleInfoText;
        }
Exemplo n.º 4
0
 void Awake()
 {
     watchRadialMenu = SteamVR_Input.GetBooleanAction("WatchRadialMenu");
     toggleWatchMode = SteamVR_Input.GetBooleanAction("ToggleWatchMode");
     Current         = this;
     ItemEquippableEvents.OnPlayerWieldItem                 += ItemSwitched;
     InventoryAmmoEvents.OnInventoryAmmoUpdate              += AmmoUpdate;
     Controllers.HandednessSwitched                         += SetHandedness;
     VRConfig.configWatchScaling.SettingChanged             += WatchScaleChanged;
     VRConfig.configUseNumbersForAmmoDisplay.SettingChanged += AmmoDisplayChanged;
     VRConfig.configWatchColor.SettingChanged               += WatchColorChanged;
     VRConfig.configWatchInfoText.SettingChanged            += WatchRadialInfoTextChanged;
     ChatMsgEvents.OnChatMsgReceived                        += ChatMsgReceived;
 }
Exemplo n.º 5
0
        private static void InitializeActionMapping()
        {
            hapticAction              = SteamVR_Input.GetAction <SteamVR_Action_Vibration>("Haptic", false);
            m_weaponSwitchLeftAction  = SteamVR_Input.GetBooleanAction("WeaponSwitchLeft", false);
            m_weaponSwitchRightAction = SteamVR_Input.GetBooleanAction("WeaponSwitchRight", false);
            m_reloadAction            = SteamVR_Input.GetBooleanAction("Reload", false);
            m_flashlightAction        = SteamVR_Input.GetBooleanAction("ToggleFlashlight", false);
            m_shootAction             = SteamVR_Input.GetBooleanAction("Shoot", false);
            m_movementAxisAction      = SteamVR_Input.GetVector2Action("Movement", false);
            m_interactAction          = SteamVR_Input.GetBooleanAction("interact", false);
            m_crouchAction            = SteamVR_Input.GetBooleanAction("Crouch", false);
            m_sprintAction            = SteamVR_Input.GetBooleanAction("Sprint", false);
            m_jumpAction              = SteamVR_Input.GetBooleanAction("Jump", false);
            m_openMapAction           = SteamVR_Input.GetBooleanAction("OpenMap", false);
            m_openMenuAction          = SteamVR_Input.GetBooleanAction("OpenMenu", false);
            m_pingAction              = SteamVR_Input.GetBooleanAction("Ping", false);
            m_openObjectivesAction    = SteamVR_Input.GetBooleanAction("OpenObjectives", false);
            m_aimOrShoveAction        = SteamVR_Input.GetBooleanAction("AimOrShove", false);
            m_pushToTalkAction        = SteamVR_Input.GetBooleanActionFromPath("/actions/default/in/PushToTalk");


            boolActions = new Dictionary <InputAction, SteamVR_Action_Boolean>
            {
                { InputAction.Jump, m_jumpAction },
                { InputAction.Use, m_interactAction },
                { InputAction.Aim, m_aimOrShoveAction },
                { InputAction.ToggleObjectives, m_openObjectivesAction },
                { InputAction.Fire, m_shootAction },
                { InputAction.Run, m_sprintAction },
                { InputAction.Crouch, m_crouchAction },
                { InputAction.Reload, m_reloadAction },
                { InputAction.VoiceChatPushToTalk, m_pushToTalkAction },
                { InputAction.NavMarkerPing, m_pingAction },
                { InputAction.TerminalUp, m_weaponSwitchLeftAction },
                { InputAction.TerminalDown, m_weaponSwitchRightAction },
                { InputAction.TerminalExit, m_reloadAction },
                { InputAction.MenuClick, m_shootAction },
                //{ InputAction.MenuClickAlternate, interactAction },
                { InputAction.MenuExit, m_reloadAction },
                { InputAction.MenuToggle, m_openMenuAction },
                { InputAction.ToggleMap, m_openMapAction },
                { InputAction.Flashlight, m_flashlightAction },
            };
        }
Exemplo n.º 6
0
        private void InitializeActionMapping()
        {
            hapticAction            = SteamVR_Input.GetAction <SteamVR_Action_Vibration>("Haptic", false);
            weaponSwitchLeftAction  = SteamVR_Input.GetBooleanAction("WeaponSwitchLeft", false);
            weaponSwitchRightAction = SteamVR_Input.GetBooleanAction("WeaponSwitchRight", false);
            reloadAction            = SteamVR_Input.GetBooleanAction("Reload", false);
            flashlightAction        = SteamVR_Input.GetBooleanAction("ToggleFlashlight", false);
            snapLeftAction          = SteamVR_Input.GetBooleanAction("SnapTurnLeft", false);
            snapRightAction         = SteamVR_Input.GetBooleanAction("SnapTurnRight", false);
            shootAction             = SteamVR_Input.GetBooleanAction("Shoot", false);
            toggleWatchAction       = SteamVR_Input.GetBooleanAction("ToggleWatchMode", false);
            movementAxisAction      = SteamVR_Input.GetVector2Action("Movement", false);
            interactAction          = SteamVR_Input.GetBooleanAction("interact", false);
            crouchAction            = SteamVR_Input.GetBooleanAction("Crouch", false);
            sprintAction            = SteamVR_Input.GetBooleanAction("Sprint", false);
            jumpAction     = SteamVR_Input.GetBooleanAction("Jump", false);
            openMapAction  = SteamVR_Input.GetBooleanAction("OpenMap", false);
            openMenuAction = SteamVR_Input.GetBooleanAction("OpenMenu", false);
            pingAction     = SteamVR_Input.GetBooleanAction("Ping", false);


            VRInput.boolActions = new Dictionary <InputAction, SteamVR_Action_Boolean>
            {
                { InputAction.Jump, jumpAction },
                { InputAction.Use, interactAction },
                { InputAction.Aim, toggleWatchAction },
                { InputAction.Fire, shootAction },
                { InputAction.Run, sprintAction },
                { InputAction.Crouch, crouchAction },
                { InputAction.Reload, reloadAction },
                //{ InputAction.Melee, aimAction },
                { InputAction.NavMarkerPing, pingAction },
                { InputAction.TerminalUp, weaponSwitchLeftAction },
                { InputAction.TerminalDown, weaponSwitchRightAction },
                { InputAction.TerminalExit, reloadAction },
                { InputAction.MenuClick, shootAction },
                { InputAction.MenuClickAlternate, interactAction },
                { InputAction.MenuExit, reloadAction },
                { InputAction.MenuToggle, openMenuAction },
                { InputAction.ToggleMap, openMapAction },
                { InputAction.Flashlight, flashlightAction }
            };
        }
Exemplo n.º 7
0
        void UpdateUserPresence()
        {
            switch (platformManager.Platform)
            {
            case PlatformID.None:
                break;

            case PlatformID.Oculus:
                userPresence = OVRManager.isHmdPresent;
                break;

            case PlatformID.SteamVR:
                SteamVR_Action_Boolean headsetOnHead = SteamVR_Input.GetBooleanAction("headsetonhead");
                userPresence = headsetOnHead.GetState(SteamVR_Input_Sources.Head);
                break;

            default:
                break;
            }
        }
Exemplo n.º 8
0
 // Update is called once per frame
 void Update()
 {
     grabState = SteamVR_Input.GetBooleanAction("GrabPinch").GetState(SteamVR_Input_Sources.RightHand);
 }
Exemplo n.º 9
0
    protected override void FillMetadata(HandAnchor anchor, ref XRNodeState xRNode)
    {
        //base.UpdateHandNodeState(hand, ref xRNode);
        float thumb = 0f, index = 0f, middle = 0f;

        //psotion && rotation
        xRNode.TryGetPosition(out anchor.position);
        xRNode.TryGetRotation(out anchor.rotation);

        var    inputSource      = SteamVR_Input_Sources.LeftHand;
        string skeletonHandName = "SkeletonLeftHand";

        if (anchor.type == NodeType.RightHand)
        {
            inputSource      = SteamVR_Input_Sources.RightHand;
            skeletonHandName = "skeletonRightHand";
        }

        //SteamVR_Action_Boolean key_MenuKey = SteamVR_Input.GetBooleanAction("MenuKey");
        //SteamVR_Action_Boolean key_SystemKey = SteamVR_Input.GetBooleanAction("SystemKey");

        //trigger
        SteamVR_Action_Boolean triggerPressed = SteamVR_Input.GetBooleanAction("Trigger");

        //SteamVR_Action_Single triggerTouchValue = SteamVR_Input.GetSingleAction("triggerTouchValue");
        anchor.triggerPressed    = triggerPressed.GetState(inputSource);
        anchor.triggerTouchValue = Mathf.Lerp(anchor.triggerTouchValue, anchor.triggerPressed ? 1f : 0f, Time.deltaTime * 5);
        index = anchor.triggerTouchValue;

        //grip
        SteamVR_Action_Boolean gripPressed = SteamVR_Input.GetBooleanAction("SideTrigger");

        //SteamVR_Action_Single gripTouchValue = SteamVR_Input.GetSingleAction("gripTouchValue");
        anchor.gripPressed    = gripPressed.GetState(inputSource);
        anchor.gripTouchValue = Mathf.Lerp(anchor.gripTouchValue, anchor.gripPressed ? 1f : 0f, Time.deltaTime * 5);
        middle = anchor.gripTouchValue;

        //primary2DAxis
        SteamVR_Action_Vector2 primary2DAxis      = SteamVR_Input.GetVector2Action("ThumbStick");
        SteamVR_Action_Boolean primary2DAxisClick = SteamVR_Input.GetBooleanAction("PadDown");

        anchor.primary2DAxis        = primary2DAxis.GetAxis(inputSource);
        anchor.primary2DAxisTouch   = anchor.primary2DAxis.sqrMagnitude > 0.02f;
        anchor.primary2DAxisPressed = primary2DAxisClick.GetState(inputSource);
        thumb = Mathf.Max(thumb, (anchor.primary2DAxisPressed || anchor.primary2DAxisTouch) ? 1f : 0f);
        thumb = Mathf.Max(thumb, anchor.primary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);

        //primary
        SteamVR_Action_Boolean primaryPressed = SteamVR_Input.GetBooleanAction("BKey");

        anchor.primaryPressed    = primaryPressed.GetState(inputSource);
        anchor.primaryTouchValue = (anchor.primaryPressed) ? 1f : 0f;
        thumb = Mathf.Max(thumb, anchor.primaryTouchValue);

        //secondary
        SteamVR_Action_Boolean secondaryPressed = SteamVR_Input.GetBooleanAction("AKey");

        anchor.secondaryPressed    = secondaryPressed.GetState(inputSource);
        anchor.secondaryTouchValue = (anchor.secondaryPressed) ? 1f : 0f;
        thumb = Mathf.Max(thumb, anchor.secondaryTouchValue);

        //fingers
        var skeletonHand = SteamVR_Input.GetAction <SteamVR_Action_Skeleton>(skeletonHandName);

        if (skeletonHand.poseIsValid)
        {
            anchor.handPoseChanged = skeletonHand.poseChanged;
            anchor.fingerCurls[0]  = skeletonHand.thumbCurl;
            anchor.fingerCurls[1]  = skeletonHand.indexCurl;
            anchor.fingerCurls[2]  = skeletonHand.middleCurl;
            anchor.fingerCurls[3]  = skeletonHand.ringCurl;
            anchor.fingerCurls[4]  = skeletonHand.pinkyCurl;
        }
        else
        {
            anchor.handPoseChanged = true;
            anchor.fingerCurls[0]  = thumb;
            anchor.fingerCurls[1]  = index;
            anchor.fingerCurls[2]  = middle;
            anchor.fingerCurls[3]  = middle;
            anchor.fingerCurls[4]  = middle;
        }
    }
Exemplo n.º 10
0
 // Start is called before the first frame update.
 void Start()
 {
     select = SteamVR_Input.GetBooleanAction("SelectRobotWithLaser");
 }
Exemplo n.º 11
0
 private void Start()
 {
     Trigger = SteamVR_Input.GetBooleanAction("Trigger");
     RTC     = GetComponentInChildren <RotateTowardsCamera>();
 }
Exemplo n.º 12
0
    // Update is called once per frame
    void Update()
    {
        anchorUIToLeftController();
        Vector3 raycastStart = rightHand.transform.position;
        //Vector3 raycastDir = (playerCameraContainer.transform.rotation * initialCameraForward).normalized;
        Vector3 raycastDir = rightHand.transform.forward.normalized;
        // just need to show if its true (pressed or held down)
        bool usingSelectInput = SteamVR_Input.GetBooleanAction("SelectInput").GetState(SteamVR_Input_Sources.RightHand);
        // only want to know if pressed
        bool usingCommandInput = SteamVR_Input.GetBooleanAction("CommandInput").GetStateDown(SteamVR_Input_Sources.RightHand);

        bool selectHeldDown = (usingSelectInput && !SteamVR_Input.GetBooleanAction("SelectInput").GetStateUp(SteamVR_Input_Sources.RightHand) &&
                               !SteamVR_Input.GetBooleanAction("SelectInput").GetStateDown(SteamVR_Input_Sources.RightHand));

        raycastLine.SetPosition(0, raycastStart + raycastOffset);
        raycastLine.SetPosition(1, raycastStart + raycastDir * raycastLength);

        if (isBlueCastleSelected)
        {
            blueCastle.GetComponent <BlueCastle>().ShowSpawnRange();
        }
        else
        {
            blueCastle.GetComponent <BlueCastle>().HideSpawnRange();
        }

        if (usingSelectInput)
        {
            if (isRectangularSelecting)
            {
                RaycastHit hit;
                Ray        ray = new Ray(raycastStart + raycastOffset, raycastDir);
                if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_FLOOR)))
                {
                    rectangularSelectingEnd = hit.point;
                    clearHoveredUnits();

                    List <Collider> colliders = rectangularSelectionBox.GetComponent <OverlapBox>().GetColliders();
                    foreach (Collider collider in colliders)
                    {
                        GameObject currObj = collider.gameObject;

                        if (currObj && currObj.layer == LayerMask.NameToLayer(LAYER_SOLDIER) && currObj.GetComponent <TeamColors>().IsBlueTeam()) // Hover blue soldiers
                        {
                            hoverUnit(currObj);
                        }

                        /*
                         * else if (currObj.layer == LayerMask.NameToLayer(LAYER_CASTLE) && currObj.GetComponent<TeamColors>().IsBlueTeam()) // Hover blue castle
                         * {
                         *  clearHoveredUnits();
                         *  hoverUnit(currObj);
                         *  blueCastle.GetComponent<BlueCastle>().ShowSpawnRange();
                         *  break;
                         * }
                         */
                    }
                }
            }
            else if (selectHeldDown)
            {
                RaycastHit hit;
                Ray        ray = new Ray(raycastStart + raycastOffset, raycastDir);
                if (!isDraggingSlider)
                {
                    if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_UNIT_UI)))
                    {
                        sliderInitialPos = rightHand.transform.localPosition;
                        isDraggingSlider = true;
                    }
                }
                else
                {
                    Vector3 deltaPos = calculateCurrFramePositionDelta(rightHand);
                    blueCastle.GetComponent <BlueCastle>().changeSliderValue(-deltaPos.x / 50.0f);
                }
            }
            else
            {
                RaycastHit hit;
                Ray        ray = new Ray(raycastStart + raycastOffset, raycastDir);
                if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_FLOOR)))
                {
                    rectangularSelectingStart = hit.point;
                    rectangularSelectingEnd   = hit.point;
                    isRectangularSelecting    = true;
                }
                if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_UNIT_UI)))
                {
                    //if (currObj.layer == LayerMask.NameToLayer(LAYER_UNIT_UI) && currObj.GetComponent<TeamColors>().IsBlueTeam()) // Select blue castle
                    //{
                    //    clearSelectedUnits();
                    //    dehoverUnit(currObj);
                    //    selectUnit(currObj);
                    //}
                }

                if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_CASTLE, LAYER_SOLDIER, LAYER_FLOOR, LAYER_UNIT_UI)))
                {
                    GameObject currObj = hit.transform.gameObject;

                    if (currObj.layer == LayerMask.NameToLayer(LAYER_FLOOR)) // Deselect by clicking floor
                    {
                        clearSelectedUnits();
                    }
                    else if (currObj.layer == LayerMask.NameToLayer(LAYER_SOLDIER) && currObj.GetComponent <TeamColors>().IsBlueTeam()) // Select blue soldiers
                    {
                        currObj.GetComponents <AudioSource>()[0].Play();
                        dehoverUnit(currObj);
                        selectUnit(currObj);
                        if (isBlueCastleSelected)
                        {
                            deselectUnit(blueCastle);
                        }
                    }
                    else if (currObj.layer == LayerMask.NameToLayer(LAYER_CASTLE) && currObj.GetComponent <TeamColors>().IsBlueTeam()) // Select blue castle
                    {
                        clearSelectedUnits();
                        dehoverUnit(currObj);
                        selectUnit(currObj);
                    }
                }
            }
            // release all boolean
            if (SteamVR_Input.GetBooleanAction("CommandInput").GetStateUp(SteamVR_Input_Sources.RightHand))
            {
                isRectangularSelecting = false;
                isBlueCastleSelected   = false;
                isUnitUISelected       = false;
            }
        }
        else if (usingCommandInput)
        {
            RaycastHit hit;
            Ray        ray = new Ray(raycastStart + raycastOffset, raycastDir);

            if (!isBlueCastleSelected && Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_CASTLE)))
            {
                if (hit.transform.gameObject.GetComponent <TeamColors>().IsBlueTeam())
                {
                    blueCastle.GetComponent <BlueCastle>().toggleBaseMenu();
                }
            }

            if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_UNIT_UI)))
            {
                blueCastle.GetComponent <BlueCastle>().toggleCurrentUnit();
            }

            if (isBlueCastleSelected && Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_FLOOR)))
            {
                blueCastle.GetComponent <BlueCastle>().SpawnSoldierInRange(hit.point);
            }
            else if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_CASTLE)))
            {
                if (hit.transform.gameObject.GetComponent <TeamColors>().IsRedTeam())
                {
                    AttackWithSelectedUnits(hit.transform.gameObject);
                }
            }
            else if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_RESOURCE)))
            {
                GatherWithSelectedUnits(hit.transform.gameObject);
            }
            else if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_SOLDIER)))
            {
                if (hit.transform.gameObject.GetComponent <TeamColors>().IsRedTeam())
                {
                    AttackWithSelectedUnits(hit.transform.gameObject);
                }
            }
            else if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_FLOOR)))
            {
                DefendWithSelectedUnits(hit.point);
            }
        }
        else
        {
            if (isRectangularSelecting) // Complete rectangular selection
            {
                isRectangularSelecting = false;

                List <GameObject> toSelect = new List <GameObject>();
                foreach (GameObject hovered in hoveredUnits)
                {
                    if (!selectedUnits.Contains(hovered))
                    {
                        toSelect.Add(hovered);
                    }
                    hovered.GetComponents <AudioSource>()[0].Play();
                }

                clearHoveredUnits();
                foreach (GameObject hovered in toSelect)
                {
                    selectUnit(hovered);
                }
            }
            else // Single unit hover
            {
                clearHoveredUnits();
                RaycastHit hit;
                Ray        ray = new Ray(raycastStart + raycastOffset, raycastDir);
                if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_CASTLE, LAYER_SOLDIER, LAYER_RESOURCE)))
                {
                    GameObject currObj = hit.transform.gameObject;

                    if (!selectedUnits.Contains(currObj))
                    {
                        hoverUnit(currObj);
                        if (currObj.layer == LayerMask.NameToLayer(LAYER_CASTLE))
                        {
                            blueCastle.GetComponent <BlueCastle>().ShowSpawnRange();
                        }
                    }
                }
            }
        }

        if (isRectangularSelecting)
        {
            rectangularSelectionLine.gameObject.SetActive(true);
            float xDiff = rectangularSelectingEnd.x - rectangularSelectingStart.x;
            float zDiff = rectangularSelectingEnd.z - rectangularSelectingStart.z;
            rectangularSelectionLine.SetPosition(0, rectangularSelectingStart + new Vector3(0.0f, 0.5f, 0.0f));
            rectangularSelectionLine.SetPosition(1, rectangularSelectingStart + new Vector3(xDiff, 0.5f, 0.0f));
            rectangularSelectionLine.SetPosition(2, rectangularSelectingEnd + new Vector3(0.0f, 0.5f, 0.0f));
            rectangularSelectionLine.SetPosition(3, rectangularSelectingStart + new Vector3(0.0f, 0.5f, zDiff));
            rectangularSelectionLine.SetPosition(4, rectangularSelectingStart + new Vector3(0.0f, 0.5f, 0.0f));

            rectangularSelectionBox.gameObject.SetActive(true);
            rectangularSelectionBox.transform.position   = rectangularSelectingStart + new Vector3(xDiff / 2.0f, 0.0f, zDiff / 2.0f);
            rectangularSelectionBox.transform.localScale = new Vector3(Mathf.Abs(xDiff), rectangularSelectionBox.transform.localScale.y, Mathf.Abs(zDiff));
        }
        else
        {
            rectangularSelectionLine.gameObject.SetActive(false);
            rectangularSelectionBox.gameObject.SetActive(false);
        }

        listenAndCastMeteor();
        listenAndExecuteFlying();
    }