public void checkPress()
    {
        if (isPositioning)
        {
            hideButtons();

            string name = ElementPlacing.truncateNumbers(placedElem.name);

            if (ep.getObjectNum(name) < transform.GetComponent <InvOpen>().panel.GetComponent <AvailElemManager>().getCount(name))
            {
                ElementPlacing.currHold = ElementPlacing.truncateNumbers(placedElem.name);
                ElementPlacing.holding  = true;
            }

            if (!PlaySimulation.isSimActive)
            {
                if (placedElem.name.Contains("ramp"))
                {
                    BlockHover.showRampGrid();
                }
                else
                {
                    BlockHover.showGrid();
                }
            }
            //BlockHover.hideRampGrid ();
            ep.canPlace = true;
            placedElem  = null;
        }
    }
    public void TakeElement(string elem)
    {
        if (elem == "ramp")
        {
            BlockHover.showRampGrid();
            BlockHover.hideGrid();
        }
        else
        {
            BlockHover.showGrid();
            BlockHover.hideRampGrid();
        }
        holding  = true;
        currHold = elem;
        if (elem == "remove")
        {
            removeToggle = !removeToggle;
            if (!removeToggle)
            {
                holding = false;
            }
        }

        var manager = GameObject.Find("UIManager");

        if (manager.GetComponent <InvOpen> ().open)
        {
            manager.GetComponent <InvOpen> ().open = false;
            panel.transform.Translate(panel.transform.right * 135 * canvas.GetComponent <Canvas>().scaleFactor);
            panel.transform.Find("InventoryArrow").Rotate(0, 0, 180);
        }
    }
 public void RemoveElem()
 {
     if (placedElem.GetComponent <ElementProperties> ().removable)
     {
         ElementPlacing.currHold = ElementPlacing.truncateNumbers(placedElem.name);
         ElementPlacing.holding  = true;
         if (placedElem.name.Contains("ramp"))
         {
             BlockHover.showRampGrid();
             BlockHover.hideGrid();
         }
         else
         {
             BlockHover.showGrid();
             BlockHover.hideRampGrid();
         }
         ep.decNum(placedElem.name);
         Destroy(placedElem);
         placedElem  = null;
         ep.canPlace = true;
     }
 }
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (canPlace && !PlaySimulation.isSimActive && (!EventSystem.current.IsPointerOverGameObject()))
            {
                Vector2 mousePos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                Ray     ray;
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                Vector3    pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                allowPlacing();

                BlockHover.hideGrid();
                BlockHover.hideRampGrid();
                if (Physics.Raycast(ray, out hit, 100))
                {
                    bool placed = false;
                    if (holding)
                    {
                        if (hit.collider.gameObject != null && (hit.collider.gameObject.tag == "Spawned Objects"))
                        {
                            Positioning.placedElem = hit.collider.gameObject;
                            activateButtons();
                        }
                        else
                        {
                            bool hitGround     = false;
                            bool hitRampGround = false;
                            foreach (Transform child in ground.transform)
                            {
                                Bounds bounds = child.GetComponent <MeshCollider> ().bounds;
                                if (bounds.Contains(hit.point))
                                {
                                    hitGround = true;
                                    break;
                                }
                            }

                            if (!hitGround && rampGround != null)
                            {
                                foreach (Transform child in rampGround.transform)
                                {
                                    Bounds bounds = child.GetComponent <MeshCollider> ().bounds;
                                    if (bounds.Contains(hit.point))
                                    {
                                        hitRampGround = true;
                                        break;
                                    }
                                }
                            }

                            if ((hitGround || hitRampGround) && !overlaping(hit.point))
                            {
                                var script = invPanel.GetComponent <AvailElemManager> ();

                                GameObject newObj = null;

                                if ((currHold == "ramp") && hitRampGround)
                                {
                                    BlockHover.showRampGrid();
                                    BlockHover.hideGrid();
                                    foreach (Transform child in GameObject.Find("RampGridBlocks").transform)
                                    {
                                        if (child.gameObject.GetComponent <BlockHover> ().checkMouseOver())
                                        {
                                            newObj = Instantiate(ramp);
                                            rampNum++;
                                            newObj.name = "ramp" + rampNum;
                                            newObj.transform.position = new Vector3(Mathf.Round(hit.point.x), hit.point.y + 0.18f, Mathf.Round(hit.point.z));

                                            newObj.transform.rotation = child.rotation;
                                            newObj.transform.position = child.position;
                                            placed = true;
                                            break;
                                        }
                                    }
                                }
                                else if (currHold == "curve" && hitGround)
                                {
                                    newObj = Instantiate(curve);
                                    curveNum++;
                                    newObj.name = "curve" + curveNum;
                                    newObj.transform.position = new Vector3(Mathf.Round(hit.point.x), hit.point.y + 0.375f - 0.12f, Mathf.Round(hit.point.z));
                                    placed = true;
                                }
                                if (placed && newObj)
                                {
                                    newObj.transform.parent = spawnedObjects.transform;
                                    Positioning.placedElem  = newObj;
                                    activateButtons();
                                }
                            }
                        }
                    }

                    if (!placed && hit.collider.gameObject && (hit.collider.gameObject.tag == "Spawned Objects"))
                    {
                        if (hit.collider.gameObject.name.Contains("ramp"))
                        {
                            BlockHover.showRampGrid();
                            BlockHover.hideGrid();
                        }
                        else
                        {
                            BlockHover.showGrid();
                            BlockHover.hideRampGrid();
                        }

                        Positioning.placedElem = hit.collider.gameObject;
                        activateButtons();
                    }
                }
                preventPlacing();
                if (holding && Positioning.placedElem == null)
                {
                    if (currHold == "ramp")
                    {
                        BlockHover.showRampGrid();
                        BlockHover.hideGrid();
                    }
                    else
                    {
                        BlockHover.showGrid();
                        BlockHover.hideRampGrid();
                    }
                }
            }
        }
    }