0
votes

i have a small problem with OnMouseDown function. It doesnt detect my mouse clicks after i move the camera. Here is my camera moving script:

        if(Input.GetKey(KeyCode.D))
    {
        Camera.main.transform.position = new Vector2(10 * Time.deltaTime, 0);
    }
    if (Input.GetKey(KeyCode.A))
    {
        Camera.main.transform.position = new Vector2(-10 * Time.deltaTime, 0);
    }

So, when i enter the game and dont click "A" nor "D" button, everything works fine. However, when i click it OnMouseDown function stops detecting my clicks. In addition to that my gamemobjects that have a script with OnMouseDown function after moving the camera visually change size, as seen here.

So what my game do is I instantiate a prefab few times (lits say 100). This prefab has script with OnMouseDown attached to it. My Camera movement script is attached to main camera. There is no direct references between prefab script and camera control script. What OnMouseDown basicaly do is loads up data from clicked object and show it on screen.

Thanks for any help!

1
Hi and welcome to Stack Overflow! Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers, and currently there is not enough information to reproduce your problem See: How to create a Minimal, Reproducible Example.Ruzihm
Thanks! i have just edited my post. I hope its better now.Rounix

1 Answers

1
votes

Ok, so i managed to fix it! For future generations, you should replace Vector2() with Vector3()