Esempio n. 1
0
    void checkForParent()
    {
        LevelBlockManipulation lb = null;

        if (dimension != null)
        {
            dimension.transform.parent.TryGetComponent <LevelBlockManipulation>(out lb);
        }

        if (lb == null || lb.isMoving == false)
        {
            RaycastHit hit;
            LayerMask  mask = 1 << gameObject.layer;

            // the player needs to be on the "Up" layer for this to work
            if (Physics.Raycast(transform.position, -transform.up, out hit, 10, mask, QueryTriggerInteraction.Ignore))
            {
                Transform currentObject = hit.transform;
                bool      notFound      = true;
                Transform g             = currentObject;
                while (currentObject != null && notFound)
                {
                    if (currentObject.tag == "WallHolder" || currentObject == gameObject)
                    {
                        break;
                    }
                    if (currentObject.TryGetComponent <Dimension>(out Dimension dim))
                    {
                        if (dim.GetComponentInParent <LevelBlockManipulation>().isMoving == false && (dimension == null || dimension.transform.parent != dim.transform.parent))
                        {
                            transform.SetParent(dim.transform);
                            checkSetDimension(dim);
                            notFound = false;
                            print(g.gameObject);
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        currentObject = currentObject.parent;
                    }
                }
                if (hit.distance <= halfHeight + 0.01)
                {
                    isGrounded = true;
                }
                else
                {
                    isGrounded = false;
                }
            }
            else
            {
                isGrounded = false;
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Uses raycasts to select movable blocks
    /// </summary>
    void CheckBlockClick()
    {
        if (Input.GetMouseButtonDown(0))
        {
            int        layerMask = LayerMask.GetMask("Water");
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 100, layerMask, QueryTriggerInteraction.Collide))
            {
                if (selectedManipulationScript != null) //make sure nothing is selected
                {
                    selectedManipulationScript.Selected(false);
                    selectedManipulationScript = null;
                }

                if (hit.transform.TryGetComponent(out selectedManipulationScript))//select a movable block if it can
                {
                    selectedManipulationScript.Selected(true, hit.point);
                }
            }
        }
        if (Input.GetMouseButtonUp(0))//release movable block
        {
            if (selectedManipulationScript != null)
            {
                selectedManipulationScript.Selected(false);
                selectedManipulationScript = null;
            }
        }
    }
Esempio n. 3
0
 void UnselectDimension()
 {
     if (selectedManipulationScript != null)
     {
         selectedManipulationScript.Selected(false);
         selectedManipulationScript = null;
         hasSelectedDimension       = false;
     }
     selectorReset = false;
     DestroyDirectionIndicator();
 }
Esempio n. 4
0
    void SelectDimension()
    {
        Vector3    mouseMovedFromCenter = Vector3.zero;
        int        layerMask            = LayerMask.GetMask("Water");
        RaycastHit hit;
        Ray        ray = new Ray(transform.position, -transform.up);

        if (Physics.Raycast(ray, out hit, 5, layerMask, QueryTriggerInteraction.Collide))
        {
            if (selectedManipulationScript != null) //make sure nothing is selected
            {
                UnselectDimension();
            }

            if (hit.transform.TryGetComponent(out selectedManipulationScript))//select a movable block if it can
            {
                selectedManipulationScript.Selected(true, hit.point);
                hasSelectedDimension = true;
                SpawnDirectionIndicator();
            }
            else if (highlightedManipulationScript != null)
            {
                selectedManipulationScript = highlightedManipulationScript;
                selectedManipulationScript.Selected(true, hit.point);
                hasSelectedDimension = true;
                SpawnDirectionIndicator();
            }
            else
            {
                MoveSelector();
            }
        }
        else if (highlightedManipulationScript != null)
        {
            selectedManipulationScript = highlightedManipulationScript;
            selectedManipulationScript.Selected(true, hit.point);
            hasSelectedDimension = true;
            SpawnDirectionIndicator();
        }
        else
        {
            MoveSelector();
        }
    }