- Home /
The question is answered, right answer was accepted
After loading scene raycast2D script doesn't detect all clicks
Whenever I go from the main menu to the playable scene some of the gameobjects don't get detected when I click on them (gif in attachment). I don't know why this happens. All the buttons do is change a playerPref called "Difficulty" and according to what difficulty it is it changes the number of pieces instantiated, that's it, nothing else changes
This is the script that opens that small Hotbar at the bottom:
void AbrirHotbar()//Opens the "Hotbar" where all the movement cards are located
{
if (Input.GetMouseButtonDown(0))
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
if (hit.transform.gameObject == gameObject && !Hotbar.activeSelf)
{
//FillImages();
Hotbar.SetActive(true);
Highlight.SetActive(true);
}
else if (hit.transform.gameObject.CompareTag("TilePeça") && Hotbar.activeSelf)
{
Hotbar.SetActive(false);
Highlight.SetActive(false);
}
}
}
Any help on why this could be happening would be greatly appreciated.
Thank you for your time!
Do all game objects have same Z position? I had quite similar issue and i solved it by decreasing Z position of game objects to like -100. $$anonymous$$aybe it might help
Yeah all of them had the same z (0), I tried moving the whole grid back 1 unit and now everything seems to work fine. Thank you so much!
Follow this Question
Related Questions
Transition between levels using 2d colider works once but not repeatidly. 1 Answer
UnityEngine.SceneManagement contains no methods? 1 Answer
How do I stop the scene from switching when the gameObject is destroy / 0 Answers
Custom 'wipe' Transition between scenes 1 Answer
Multiple Cars not working 1 Answer