Question by
StefanWullems · Jul 18, 2017 at 07:52 AM ·
raycastraycasthit2d
raycasting in 2d
Hey, I'm making a 2D sort of top down gravity game. In which I have to cast a ray from the camera toward my playing field I had it running perfectly a while ago but converting the code to be a fit for touchscreen input makes things a bit complicated for me.
This is my code, it doesn't seem to progress towards my debug.log that's logging "3" no matter what I try
if (Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0)) {
touchesOld = new GameObject[touchList.Count];
touchList.CopyTo(touchesOld);
touchList.Clear();
Ray ray = GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
bool isHit = Physics.Raycast(ray, Mathf.Infinity);
Debug.Log(ray.direction);
if (isHit) {
GameObject GOHit = hit.transform.gameObject;
touchList.Add(GOHit);
Debug.Log("3");
Comment