Hello, I've been working on this simple 2D clicking game. But basically the objects randomly don't register like, that's just how it feels when clicking them. It may be just part of the game engine or something. But I was wondering if anyone could shed some light on this. I have attached a couple pictures, One is just how the game looks when playing. Second is collider & rigid body information, I've made the collider a lot bigger than the actual object and it sort of feels better. But basically what I'm asking is that does anyone know of a way I can make it play better? Also here is my object destroy script, it is very basic. Code (CSharp): public class DestroyOnBubble : MonoBehaviour { public void OnMouseDown() { Destroy(gameObject); TimeLeft.timeLeft += 1f; ScoreScript.scoreValue += 100; if (ScoreScript.scoreValue == 1000) { SceneManager.LoadScene(2); ScoreScript.scoreValue = 0; TimeLeft.timeLeft = 15; } } } Ignore the Scorescript stuff.
you're probably missing some raycasters or have some your shouldn't. add a raycast component to your bubbles should help. see if you can find areas where your clicks are not registering correctly (such as near the overlay text or other invisible objects) and ensure you remove raycasting from them (canvasgroup component with interactable false). otherwise you might need to explain in more detail what exactly doesnt work (randomly isn't exactly fixable)
Thanks for the reply, I not using any raycast at all. I've added a raycast to the bubble and it seems better. But there is defiantly still hit reg problems. Let me try to explain the problem more clearly. Basically when playing throughout a level, when you destroy a bubble sometimes to seems to work perfectly fine. But it seems to when you try to go really fast and spam click the objects it doesn't seem to register them getting clicked that well. Here's the raycast I'm using. Code (CSharp): private void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { if (hit.collider.gameObject == gameObject) Destroy(gameObject); } } }
Are you sure there's not more than a single collider where you click. Physics queries have no concept of rendering depth i.e. they won't give you the collider that you perceive as being closer due to some other component rendering that way. You can use queries that return multiple results and check each result if that's perhaps the case here. Either that or use the LayerMask to only select specific layers. Also note that when checking if a collider is over a point, you really shouldn't be using raycast although it's use a lot by users, probably because it's used widely in 3D physics. Anyway, you should consider using the method designed for this which is OverlapPoint. You probably know this but GetMouseButtonDown is only true if you clicked it that frame. I presume this is what you want. That's all I've got for now.