I asked a question yesterday about picking up some boxes someone kindly helped me and the code i have looks like this:
var holdingAnItem : boolean;
var itemCurrentlyHeld : Transform;
var headCamera : Transform;
var pickupRange : float;
var carryOffset : Vector3; // position of a carried object relative to the camera
function Update () {
if (holdingAnItem && itemCurrentlyHeld) {
itemCurrentlyHeld.position = headCamera.position + carryOffset;
itemCurrentlyHeld.rotation = headCamera.rotation;
}
}
function Pickup () {
if (holdingAnItem) { return; } // stop if we're already holding something
var hit : RaycastHit;
if (Physics.Raycast(headCamera.position, headCamera.forward, hit, pickupRange)) {
if (hit.collider.CompareTag("carryable")) {
itemCurrentlyHeld = hit.collider.transform;
holdingAnItem = true;
}
}
}
function Drop () {
if (!holdingAnItem) { return; } // stop if we're not holding anything
itemCurrentlyHeld = transform;
holdingAnItem = false;
}
ive tagged the boxes and applied this code to the play/character. if i walk up to the box nothing happens, however if i check the box next to holding and item in the inspector it works how i want.
why is it not picking up the box as i walk up to it?
i would like it to be automatic or have it so i press a button to pick up the box.
hope someone can help,
many thanks matt