Game Jam Project Object Pickup Function (WIP)
- Keshav Batra
- May 26, 2022
- 1 min read
I've been working on this pickup function for this game jam project that I'm participating in. Even though this is still a work in progress, the object does follow me whenever I'm near it and I press the E key. I did this by adding a transform and a pickup trigger and tagged the ontriggerenter and ontriggerstay as player so that the object would follow the player since its supposed to be the parent of the pickup once its picked up. Now all I have to do is make a dropping function whenever I press the E key.
{
public GameObject PlayerSprite;
public GameObject Pickup;
public Transform PickupTrigger;
public bool HasPickup;
private void OnTriggerEnter(Collider other)
{
if (PlayerSprite.CompareTag("Player"))
{
GetComponent<BoxCollider>().enabled = true;
GetComponent<Rigidbody>().useGravity = false;
}
}
private void OnTriggerStay()
{
if (Input.GetKeyDown(KeyCode.E) && !HasPickup)
{
transform.parent = GameObject.Find("Player").transform;
HasPickup = true;
GetComponent<Rigidbody>().useGravity = false;
GetComponent<BoxCollider>().enabled = true;
transform.position = PickupTrigger.position;
}
}
}
コメント