- Home /
Using unity 4.6 UI and raycast2D functionality
Hello! In my game, I have an inventory screen. I set this inventory up with some mumbo jumbo code, and now it sort of works. Problem is, I am still raycasting things that are behind my UI.
My question is quite simple: How can I get the functionality that would make it so that my raycasting would only check the UI layer when my inventory is open? I read something about layermasking, but I wanted to ask specifically about my problem here, as I am still confused on how to implement this.
Here is some of my already implemented raycast scripting:
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);
if(canMove == true) {
if(Physics2D.Raycast(ray.origin,ray.direction)) {
if(Input.GetKeyDown(KeyCode.Mouse0) && hit.collider.tag != "UnMoveable" && timeBeforeMove == 0f) {
if(openinventory.InventoryRestriction == false) {
positionHit = hit.point;
isMoving = true;
}
}
}
}
There's still some more, but I feel it is irrelevant to the question. Please ask me if you want more information! :)
At the moment I've currently just added more variables and functions into the mix to make it work like a layered thing, but it is just faking the concept in its working state, haha! Still looking to learn more about this. :)
Your answer
Follow this Question
Related Questions
Layer Mask on raycast2d not working? 1 Answer
Usage of Layer masks, what am I doing wrong? 1 Answer
Detecting that I'm clicking a unit even though I'm not? 0 Answers
Raycast ignore itself 5 Answers
Ignore one layermask question 1 Answer