Hi guys, I have a problem with raycast. I have buttons on the screen of my game, even though I use raycast, the ray goes to them. Code (CSharp): void HitFire() { Ray _ray = Camera.main.ScreenPointToRay(Input.mousePosition); int layerMask = 1 << 5; layerMask = ~layerMask; //LayerMask layerMask = ~LayerMask.GetMask("UI"); if (Physics.Raycast(_ray, out RaycastHit hit,100f,layerMask)) { if (hit.collider.gameObject.CompareTag("spider")) { Instantiate(BloodHitEffect, hit.point, Quaternion.identity); } } } Layers EDIT: I checked this function with Code (CSharp): if(EventSystem.current.currentSelectedGameObject == null) and problem solved. I've also given a button component to my UI elements in my game scene. NOT: Code (CSharp): if(EventSystem.current.currentSelectedGameObject == null) Instead of checking Code (CSharp): if(!EventSystem.current.IsPointerOverGameObject()) you can also check