top of page
Search

Pickup Function For Pyramid Puzzle

  • Writer: Keshav Batra
    Keshav Batra
  • Jun 10, 2022
  • 1 min read

I'm finally done with my pickup function for the game jam project called Pyramid Puzzle. It took was a long grueling process but I finally managed to get it done. Below is the code I used to get this working as well as what the pickup function looks like in action. Basically whenever I press the E key, I can pick up or drop the item.






{
    public GameObject PlayerSprite;
    public GameObject Pickup;
    public Transform PickupTrigger;
    public GameObject Player;
    public bool HasPickup;
    
   

    private void OnTriggerEnter(Collider other)
    {
        if (PlayerSprite.CompareTag("Player"))
        {
            //GetComponent<BoxCollider>().enabled = true;
            //GetComponent<Rigidbody>().useGravity = false;
        }
    }
    private void OnTriggerStay(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            
            if (Input.GetKeyDown(KeyCode.E))
            {
                if (!HasPickup)
                {
                    print("HasItem");
                    transform.parent = GameObject.Find("Player").transform;
                    HasPickup = true;
                    transform.position = PickupTrigger.position;
                    GetComponent<Rigidbody>().useGravity = false;
                    return;
                }
                else
                {
                    print("DropItem");
                    transform.parent = null;
                    HasPickup = false;
                    transform.position = Player.transform.position;
                    GetComponent<Rigidbody>().useGravity = true;
                    return;
                }
            }


        }
    }
}


 
 
 

Kommentare


bottom of page