So I want to be able to spawn/drop an item at a specific location only if my player is standing in a specific location.
I have been able to set up the ability to drop the item no matter where my player is at but I am unable to figure out how to drop it if my player is standing in a specific spot.
I assume this is because I can only check for keyboard input in the Update (or similar Method) and I can only check for collision in the OnTriggerEvent2d(Collider2d other) method.
Here is the code I am using to check for collision so I can pickup items and the code that I am using to drop the item:
//Picking up Items
void OnTriggerEnter2D(Collider2D other)
{
//Insures that you can only pickup 1 set of dishes at a time
if (other.gameObject.CompareTag("DirtyPlates") && !inventory.Contains("Dirty Plates"))
{
inventory.Add("Dirty Plates");
Destroy(other.gameObject);
}
//Collision Test
//This code works
if (other.gameObject.CompareTag("Collider") && inventory.Contains("Dirty Plates"))
{
Debug.Log("Collision Working");
}
}
//Dropping Items
//This is the code that isn't really working
if (other.gameObject.CompareTag("Collider") && Input.GetKeyDown(KeyCode.Keypad0) && inventory.Contains("Dirty Plates"))
{
//Spawn Dirty Plates Sprit infront of players location
Instantiate(dirtyPlates, spawnPosition.position, transform.rotation);
//And remove it from the list
inventory.Remove("Dirty Plates");
}
Thanks,
- Patrick