public void GrabAnObject(GrabbableObject grabbedObject)
 {
     isGrabbing = true;
     if (grabbedModel != null) grabbedModel.SetActive(true);
     _grabbedObject = grabbedObject;
     _grabbedObject.Grab(grabAnchor.transform, _modelRB);
 }
Пример #2
0
    // Attempts to grab the object in the player's current line of sight
    void GrabObject()
    {
        Ray        ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward * maxGrabDistance);
        RaycastHit hitInfo;

        Physics.Linecast(ray.origin, ray.origin + ray.direction * maxGrabDistance, out hitInfo, grabbablesMask);


        Color rayColor = Color.red;

        if (hitInfo.collider != null)
        {
            rayColor = Color.green;

            heldObject = hitInfo.collider.GetComponent <GrabbableObject>();
            heldObject.Grab();
        }


        Debug.DrawLine(ray.origin, ray.origin + ray.direction * maxGrabDistance, rayColor);
    }