Another Pickup Type

Here is my pick up script for anyone like me who isn’t a fan of the whole run over something to pick it up.
I left it mostly blank so that it can be easily customized.

void Update()

{

    if(Input.GetKeyDown(KeyCode.E))

    {

       //Place your item pickup info above the DestroyObject part.

        Destroy(gameObject);

    }

}

Also you will have to add a distance modifier in order for the player to have to be near it.

I was wrong. It is a bit more complicated that I made it out to be. i will include all that is need below.
first place ItemInteraction on the item ( not the empty) and player PlayerInteraction on the player. Make sure everything you want to interact with has a collider on it. this works for doors, containers, items, ect.
first is the player interaction script.

private void Update()

{

    if(Input.GetKeyDown(KeyCode.E))

    {   float interactRange =2f;

        Collider[] colliderArray = Physics.OverlapSphere(transform.position, interactRange);

        foreach(Collider collider in colliderArray)

        {

            if (collider.TryGetComponent(out ItemInteraction itemInteraction))

            {

                itemInteraction.Interact();

                Debug.Log("Interact");

            }

           

        }

       
    }

}

This is the itemInteraction script.

public void Interact()

{

     Debug.Log("E to interact");

    Destroy(gameObject);

}

Privacy & Terms