Question by
vram227 · Jun 04, 2020 at 03:38 PM ·
2d-platformerrpg-game
Cannot convert UnityEngine.Collider2d to item
I'm trying to make a 2d game and I am trying to make some code to pickup an item in the game.
public Transform PickupPoint; public LayerMask itemLayers; public float pickupRange = 10f; public Item item; void Update() { if (Input.GetKeyDown(KeyCode.Z)) { Pickup(); } }
void Pickup ()
{
Debug.Log("Trying to pick up item");
Collider2D[] pickup = Physics2D.OverlapCircleAll(PickupPoint.position, pickupRange, itemLayers);
foreach (Collider2D item in pickup)
{
Debug.Log("We got " + item.name);
//if (item.isWeapon == true)
// {
WeaponsInvtory.instance.Add(item);
// (GameObject)item.GetComponent<WeaponsInvtory>().Add(item);
// }
Destroy(gameObject);
}
}
And I keep getting the same error after searching it up online, I'm new to C# and I'm confused about what I am doing wrong.
Comment