|
i am attempting to make it so that when you collide with an object you collect it so i have this script on the object: } } } the issue is since im using the character controller it isnt registering the collision and i cant use OnControllerColliderHit as it causes me alot of issues. thanks in advance
(comments are locked)
|
|
Usually you should make the item a trigger and use OnTriggerEnter in the player or item script (the event is sent to both). But when the item has a rigidbody with Use Gravity checked, it falls through the floor. A solution is to place the trigger in a child of the main object: child an empty object to the item, add a collider (usually a sphere) and set Is Trigger. Modify the OnCollisionEnter to OnTriggerEnter like below and attach the script to the trigger, not to the item:
function OnTriggerEnter(other: Collider){
if (other.tag == "Player"){
print(parent.name); // the parent is the item
var player = other.gameObject; // the player is the "other" object
// use the parent's name to find the script stacking
var stacking = GameObject.Find(parent.name+"_model").GetComponent(stacking);
if (stacking.stackAmount >=1){
stacking.stackAmount++;
Destroy(gameObject);
} else if (Inventory.itemNum < 8){
player.GetComponent(Inventory).AddItemToInventory(gameObject);
stacking.stackAmount++;
// I suspect you should destroy the object in this case too...
}
}
}
ill try this out now and see it works, thanks for the help
May 10 '12 at 03:02 PM
chris gough
yea this works just need to make it destroy the parent object now and I am golden so thanks =D
May 10 '12 at 10:30 PM
chris gough
My bad! It should be By the way, other references like parent.name should also be altered to trasnsform.parent.name etc.
May 11 '12 at 03:56 AM
aldonaletto
Aldo, thanks for the suggestion, it works like a charm!
Jun 03 '12 at 09:08 PM
jdwieber
(comments are locked)
|
|
If it's collecting an item, try using TriggerEnter instead. Make sure you check is trigger on the item's collision component. i tried a trigger and that didn't work either, also a trigger makes it fall through the floor.
May 09 '12 at 11:04 PM
chris gough
(comments are locked)
|
