- Home /
Layer and LayerMask Variables
I have an RTS style selection box that is bugging out. It consists of 2 scripts: 1) s_Selector.cs on the main camera, where I manually select the layer from the drop-down menu. 2) s_SelectMe.cs on any potentially select-able object, regardless of their layer assignment.
By clicking It will only select objects on a defined layer if I click (correct behavior).
If I Click-Drag a selection box, it will select anything with a "s_Select_Me.cs" attached, regardless of that object's layer.
I think these are the important parts of "s_Selector.cs":
public class s_Selector : MonoBehaviour{
public LayerMask selectableLayer;
void Update(){
if (Input.GetMouseButtonDown(0)){
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out rayHit, Mathf.Infinity, selectableLayer)){
s_SelectMe selectMeScript = rayHit.collider.GetComponent<s_SelectMe>();
if (selectMeScript.currentlySelected == false){
selectedObjects.Add(rayHit.collider.gameObject);
selectMeScript.currentlySelected = true;
selectMeScript.SelectMe();
print(gameObject.layer);
}}}}}
I keep trying to add lines to the last "If", like: if (selectMeScript.currentlySelected == false && gameobject.layer == selectableLayer) . and I can put a few things in that don't throw errors, but at best I flip the issue to be By clicking it will select anything with a "s_Select_Me.cs" attached, regardless of that object's layer. If I Click-Drag a selection box, only select objects on a defined layer if I click (correct behavior).
You can see the original script being written in this fantastic tutorial: this guy on youtube
Any help would be greatly appreciated.
Your answer
Follow this Question
Related Questions
c# Raycast going off at odd angles. Unity 5 2 Answers
RaycastHit.normal 1 Answer
Detecting that I'm clicking a unit even though I'm not? 0 Answers
C# Raycast Code not working 2 Answers
Change Transparency 1 Answer