示例#1
0
    void pickUp(leftRight lr)
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, 3))
        {
            MonoBehaviour[] scripts = hit.collider.gameObject.GetComponents <MonoBehaviour>();
            if (scripts.Length > 0)
            {
                foreach (MonoBehaviour script in scripts)
                {
                    if (script is IPickable)
                    {
                        if (lr == leftRight.left)
                        {
                            if (leftHand != null)
                            {
                                DropObject(leftRight.left);
                            }
                            leftHand = placeObject(leftRight.left, hit.collider.gameObject);
                        }
                        else
                        {
                            if (rightHand != null)
                            {
                                DropObject(leftRight.right);
                            }
                            rightHand = placeObject(leftRight.right, hit.collider.gameObject);
                        }
                        return;
                    }

                    if (script is IInteractable)
                    {
                        IInteractable localScript = (IInteractable)script;
                        localScript.Activate();
                    }



                    //if(specialcaseScript)
                    //Execute special case
                }
            }

            DropObject(lr);
        }
        else
        {
            DropObject(lr);
        }
    }
示例#2
0
 private void DropObject(leftRight lr)
 {
     if (lr == leftRight.left && leftHand != null)
     {
         leftHand.GetComponent <Rigidbody>().isKinematic = false;
         leftHand.transform.parent = null;
         leftHand = null;
     }
     if (lr == leftRight.right && rightHand != null)
     {
         rightHand.GetComponent <Rigidbody>().isKinematic = false;
         rightHand.transform.parent = null;
         rightHand = null;
     }
 }
示例#3
0
 private void UseHoldingObject(leftRight lr)
 {
     if (lr == leftRight.left && leftHand != null)
     {
         leftHand.transform.position = holdPos.position;
         leftHand.GetComponent <Rigidbody>().useGravity  = false;
         leftHand.GetComponent <Rigidbody>().isKinematic = false;
     }
     if (lr == leftRight.right && rightHand != null)
     {
         rightHand.transform.position = holdPos.position;
         rightHand.GetComponent <Rigidbody>().useGravity  = false;
         rightHand.GetComponent <Rigidbody>().isKinematic = false;
     }
     StartCoroutine(retunToHand(lr));
 }
示例#4
0
    private GameObject placeObject(leftRight lr, GameObject obj)
    {
        obj.GetComponent <Rigidbody>().isKinematic = true;
        if (lr == leftRight.left)
        {
            obj.transform.position = leftHandPos.position;
            obj.transform.SetParent(leftHandPos);
        }

        if (lr == leftRight.right)
        {
            obj.transform.position = rightHandPos.position;
            obj.transform.SetParent(rightHandPos);
        }
        return(obj);
    }
示例#5
0
    IEnumerator retunToHand(leftRight lr)
    {
        yield return(new WaitForSeconds(1f));

        if (lr == leftRight.left && leftHand != null)
        {
            leftHand.GetComponent <Rigidbody>().useGravity  = true;
            leftHand.GetComponent <Rigidbody>().isKinematic = true;
            leftHand.transform.position = leftHandPos.position;
        }
        if (lr == leftRight.right && rightHand != null)
        {
            leftHand.GetComponent <Rigidbody>().useGravity  = true;
            leftHand.GetComponent <Rigidbody>().isKinematic = true;
            rightHand.transform.position = rightHandPos.position;
        }
    }