This question was
closed Mar 23, 2019 at 04:07 AM by
JukeBoxDelta for the following reason:
Figured out on my own. LayerMask was static, so didn't show in inspector. I didn't realize I needed to define the LayerMask in the inspector again.
Question by
JukeBoxDelta · Mar 23, 2019 at 03:40 AM ·
mouseclick
Get click coordinates - Code was working before, but after copy/pasting now it isn't?,
The following code was working perfectly in void Update(). I decided to put it in a new method and for some reason it didn't work when the method was called. So I copied and pasted the code back to Update() where it was before and now it's not working at all.
I'm confused because it's the exact same code in the exact same place it was before. I've looked at it line by line and I can't find a problem. Except that RaycastHit is trying to be inlined. I don't remember it asking for that before. I tried inlining it but it still doesn't work.
What am I missing?
public class DetectClick : MonoBehaviour {
public static LayerMask clickMask;
public Vector3 clickPosition;
public static Vector3 clickPosRounded;
public static Vector3 clickPosExact;
void Update()
{
if (Input.GetMouseButtonDown (0))
{
Vector3 clickPosition = -Vector3.one;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit; //this will print if I do Debug.Log(ray);
if (Physics.Raycast (ray, out hit, 500f, clickMask))
{
Debug.Log("hit"); //This line doesn't print
clickPosition = hit.point;
clickPosExact = clickPosition;
//Get exact coordinates
clickPosRounded = new Vector3(Mathf.Round(clickPosition.x), Mathf.Round(clickPosition.y), Mathf.Round(clickPosition.z));
//Get rounded coordinates to nearest whole number
}
}
}
}
Comment