- Home /
Question by
ethan200011 · Apr 19, 2020 at 01:22 PM ·
pick up object
Picking Up Items FPS
Does anyone know a simple way to pick up a item in a FPS? I have trying on my own to get it to work but with no luck.
Comment
Answer by jayghost1983 · Apr 19, 2020 at 01:24 PM
public class Item_Pickup : MonoBehaviour
{
private Item_Master itemMaster;
void OnEnable()
{
setInitialReferences();
itemMaster.eventPickUpAction += carryOutPickupActions;
}
void OnDisable()
{
itemMaster.eventPickUpAction -= carryOutPickupActions;
}
void setInitialReferences()
{
itemMaster = GetComponent<Item_Master>();
}
void carryOutPickupActions(Transform tParent)
{
transform.SetParent(tParent);
itemMaster.callEventObjectPickup();
transform.gameObject.SetActive(false);
}
}//end class
Your answer
Follow this Question
Related Questions
Box collider on a moving object-shopping cart 3 Answers
How to make a note pickup system in Unity2D? 1 Answer
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