private bool CheckScreenPoint(Vector3 screenPoint) { //Ray2D _ray2D = cam.ScreenToWorldPoint(Input.mousePosition) RaycastHit2D hit = Physics2D.Raycast(cam.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, Mathf.Infinity, _movableLayerMask.value); if (hit.collider != null) { Debug.Log("Target Position: " + hit.collider.gameObject.name); Vector3 hitWorldPos = new Vector3(hit.point.x, hit.point.y, 0); _mover.StopMoving(); _mover.MoveTowards(hitWorldPos); } else { Debug.Log("null!"); } /* * if (hitGround) * { * Vector3 hitWorldPosition = hitInfo.point; * _mover.StopMoving(); * _mover.MoveTowards(hitWorldPosition); * * * } */ return(true); }
private bool CheckScreenPoint(Vector3 screenPoint) { RaycastHit2D hit = Physics2D.Raycast(cam.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, Mathf.Infinity, _selectionLayerMask.value); if (hit.collider != null) { if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Crew")) { Debug.Log("Target Position in crew Layer: " + hit.collider.gameObject.name); //_mover = hit.collider.GetComponent<AbstractMover>(); selCrew(hit.collider.gameObject); _mover = selectedCrew.GetComponent <AbstractMover>(); } else { Debug.Log("Target Position in moving Layer: " + hit.collider.gameObject.name); Vector3 moveWorldPos = new Vector3(hit.point.x, hit.point.y, 0); _mover.StopMoving(); _mover.MoveTowards(moveWorldPos); } } else { /*RaycastHit2D facilityAssign = Physics2D.Raycast(cam.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, Mathf.Infinity, * _facilityLayerMask.value); * * if (facilityAssign.collider != null) * { * selectedCrew.GetComponent<Crew>().setAssigned(true); * } * else * { * selectedCrew.GetComponent<Crew>().setAssigned(false); * } * RaycastHit2D moveTo = Physics2D.Raycast(cam.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, Mathf.Infinity, * _movableLayerMask.value); * //Debug.Log("Target Position in moving Layer: " + moveTo.collider.gameObject.name); * Vector3 moveWorldPos = new Vector3(moveTo.point.x, moveTo.point.y, 0); * _mover.StopMoving(); * _mover.MoveTowards(moveWorldPos);*/ Debug.Log("Null"); } return(true); }