// Update is called once per frame
    void Update()
    {
        if (!IsPaused())
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, nodeMask))
            {
                // HOVERING MECHANIC
                currentNode = hit.transform.parent.gameObject.GetComponent <NodeV2>();

                if (currentNode == null)
                {
                    if (previousNode != null)
                    {
                        previousNode.GetComponentInChildren <NodeHoverV2>().StopHovering();
                        previousNode = null;
                    }
                }
                else if (previousNode == null)
                {
                    previousNode = currentNode;
                    hit.transform.gameObject.GetComponent <NodeHoverV2>().Hover();
                }
                else if (currentNode.GetInstanceID() != previousNode.GetInstanceID())
                {
                    previousNode.GetComponentInChildren <NodeHoverV2>().StopHovering();
                    hit.transform.gameObject.GetComponent <NodeHoverV2>().Hover();
                    previousNode = currentNode;
                }


                // SELECTION MECHANIC
                if (Input.GetMouseButtonDown(0))
                {
                    if (EventSystem.current.IsPointerOverGameObject())
                    {
                        return;
                    }


                    selectedNode = currentNode;

                    if (selectedNode.towerPlaced)
                    {
                        towerSelected = selectedNode.GetTowerObject();

                        //
                        //Test
                        //
                        //EventSystem.current.SetSelectedGameObject(towerSelected);
                        //
                        //Test
                        //

                        //Tower Status Additon, only for upgraded towers
                        if (towerSelected.GetComponent <TowerController>().GetTowerType() != "base_tower")
                        {
                            selectedTowerStatus.text = towerSelected.GetComponent <TowerController>().formattedName;
                            SetNextPurchaseCost(towerSelected);
                        }


                        if (!towerSelected.GetComponent <Outline>().isActiveAndEnabled)
                        {
                            towerSelected.GetComponent <Outline>().enabled = true;
                            SpawnMenu(towerSelected);
                        }
                        else
                        {
                            towerSelected.GetComponent <Outline>().enabled = false;
                            towerSelected = null;
                            DeSpawnMenu();
                        }
                    }
                }

                // 2. IF NO TOWER && SPAWNABLE, SPAWN TOWER
                else if (spawnable && selectedNode.GetIsTowerPlacable())
                {
                    Vector3 position = selectedNode.transform.position + selectedNode.GetEnvOffset();
                    selectedNode.DeleteEnvObject();
                    GameObject temp = Instantiate(towerToBuild, position, Quaternion.identity) as GameObject;
                    selectedNode.SetTowerObject(temp);

                    //Mark the node as having a placed tower
                    selectedNode.towerPlaced = true;

                    //Make tower child to Node
                    temp.transform.parent = selectedNode.transform;

                    spawnable = false;
                }
            }
        }
        else
        {
            Debug.Log(Time.timeScale);
        }
    }