private void Drop() { if (cursorObject != null) { cursorObject.CursorExit(); cursorObject = null; startHold = true; } }
private void ReactToCursor(RaycastHit hit, Vector3 direction) { // If the object has any curser interaction supported it will implement the IReactToCursor interface IReactToCursor irc = hit.transform.GetComponent <IReactToCursor>(); if (irc != null) { // If we have hit a new object this frame, if cursor was on a previous object notify that it has now left, notify new object that cursor has entered if (irc != cursorObject) { if (cursorObject != null) { cursorObject.CursorExit(); } cursorObject = irc; cursorObject.CursorEnter(hit); } // Logic for objects that can be picked up, probably should be moved to Pickupable class Pickupable pickup = hit.transform.GetComponent <Pickupable>(); if (pickup != null) { Rigidbody hitRigidBody = hit.transform.GetComponent <Rigidbody>(); // If the object is further away from the hold distance, draw towards user // (hold distance allows objects to be held a little way in front of the user) if (hit.distance > holdDistance && hitRigidBody.velocity.magnitude < maxGrabVelocity) { hitRigidBody.AddForce((direction).normalized * -pickupForce, ForceMode.Force); } else if (hit.distance <= holdDistance) { // if(startHold) hitRigidBody.velocity = Vector3.zero; // Allows user to hold object holdDistance away from hand, and allows throwing of object when let go // value of 40 just from trial & error, needs to be refined and turned into a variable hitRigidBody.velocity = ((startTransform.position + (direction).normalized * holdDistance) - hitRigidBody.position) * 40; // hitRigidBody.MovePosition(startTransform.position + (direction).normalized * holdDistance); startHold = false; } } } }