- Home /
Why won't my PickUpItem Get picked up?
My pick up item won't be picked up by my widget. it just runs through it, and I can't figure out why. I haven't been able to find any errors in my script that could be stopping this from happening. have have a copy of my script below, and if there are any errors, or anything that I might be missing, please let me know. If there isn't anything wrong with the script, could you please tell me what the issue might be. Thank you//PickUpItems : Handles any itmes lying around the world that Widget can pick Pick up. var itemType : InventoryItem; var itemAmount = 1; private var pickedUp = false; //When widget finds an item on the field function OnTriggerEnter(collider : Collider){ //Make sure that this is a player hitting the item and not an enemy var playerStatus : Widget_Status = GetComponent.().GetComponent(Widget_Status); if(playerStatus == null) return;
//Stop it from being picked up twice by accident
if(pickedUp) return;
//if everythings good, put it in widgets inventory
var widgetInventory = GetComponent.<Collider>().GetComponent(Widget_Inventory);
widgetInventory.GetItem(itemType, itemAmount);
pickedUp = true;
//get rid of it now that its in the inventory
Object.Destroy(gameObject);
} //Make sure the pickup is set up properly with a collider function Reset (){ if (GetComponent.() == null){ gameObject.AddComponent(SphereCollider); } GetComponent.().isTrigger = true; } @script AddComponentMenu("Inventory/PickupItems")
Your answer
Follow this Question
Related Questions
Box collider on a moving object-shopping cart 3 Answers
Weapon Pickup and Drop 0 Answers
Multiple GameObjects with the same script all react but I only want one at a time. 2 Answers
Setting Inventory Reference to a Object For Pickup when the Inventory is a Instantiated Prefab 1 Answer
placing an object to it's initital position after picked up. 0 Answers