Exemple #1
0
    private void PickUpObject()
    {
        // HideAllStackableObjects();
        RaycastHit hit;
        // Shoot raycast based on mouse position.
        Ray       ray       = GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);
        LayerMask layermask = 1 << (int)BaseObject.Layers.IgnoreRaycast | 1 << (int)BaseObject.Layers.AnchorPoint;

        layermask = ~layermask;
        if (Physics.Raycast(ray, out hit, 1000, layermask))
        {
            GameObject         target    = hit.transform.gameObject;
            BaseObject         usable    = target.GetComponent <BaseObject>();
            StackableComponent stackable = target.GetComponent <StackableComponent>();
            StabberComponent   stabber   = target.GetComponent <StabberComponent>();
            // If the raycast hit an anchor point, check to make sure the anchor point is not occupied.

            // check if target is attached to pivot, if not, target is not movable
            if (!IsAttachedToPivot(target))
            {
                return;
            }

            // set highlight to white
            SetLayerRecursive(target.transform.parent.gameObject, (int)BaseObject.Layers.HoldingObject);

            if (stabber && stabber.Stabbed)
            {
                stabber.Dislodge();
            }

            if (stackable && stackable.isPickupable)
            {
                if (stackable.getSpawnedAnchorPoint() != null)
                {
                    if (stackable.getSpawnedAnchorPoint().GetComponent <AnchorPoint>().IsOccupied == true)
                    {
                        return;
                    }
                }
                previousObject = target;

                heldObject.previousPointPosition = hit.point;
                heldObject.PickUpObject(target);
                ShowAllStackableObjects();
                objectisHeld = true;
            }
            else if (usable && usable.isPickupable)
            {
                previousObject = target;

                heldObject.previousPointPosition = hit.point;
                heldObject.PickUpObject(target);

                ShowAllStackableObjects();
                objectisHeld = true;
            }
        }
    }
Exemple #2
0
 private void ShowAllStackableObjects()
 {
     if (showingStackables)
     {
         return;
     }
     foreach (GameObject ap in stackablePoints)
     {
         if (ap.transform.IsChildOf(heldObject.TheHeldObject.transform.parent))
         {
             ap.SetActive(false);
         }
         else
         {
             ap.SetActive(true);
             StabberComponent stabber = ap.transform.parent.GetComponentInChildren <StabberComponent>();
             if (stabber && !stabber.Stabbed)
             {
                 ap.SetActive(false);
             }
         }
     }
     showingStackables = true;
 }