Question by
sambonibaloney · Oct 18, 2016 at 01:09 AM ·
c#unity 5unity5
OnMouseDown not working!
So I'm creating an Inventory system, and it's all set up, the last thing I have to do is make it so I can use the items. So I used OnMouseDown() to detect the clicks, and it won't detect them. I added a box collider and I even tried (out of curiousity) a button, and I made sure that there's nothing before what I'm trying to click on, but none of them worked. I restarted Unity and even remade the script, but still nothing. Does anyone know what's happening?
Here's the code:
void OnMouseDown () {
if (gameObject.name == "Peppy") {
InventoryControl.itemclicked = "y";
GetComponent<SpriteRenderer>().sprite = GetComponent<InventoryControl>().empty;
Debug.Log ("I have drank the Peppy.");
}
if (gameObject.name == "Cocola") {
GetComponent<SpriteRenderer>().sprite = GetComponent<InventoryControl>().empty;
Debug.Log ("I have drank the Cocola.");
}
}
Comment
Hello. I have the same problem. Let me know when you have the solution, thank you!