public void AddDrawingPoint() { if (m_CurrentLine == null) { return; } Vector3 newPosition = mainCamera.ScreenToWorldPoint(Input.mousePosition); newPosition.z = 0; m_CurrentLine.AddDrawingPoint(newPosition); }
public void AddDrawingPoint() { if (m_CurrentLine == null) { return; } #if UNITY_EDITOR //Get ray from camera point to mouse position Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); #else //Get ray from camera point to mouse position Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); #endif //Cast ray RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, 1000f)) { Vector3 newPosition = hitInfo.point; newPosition.y = 1; //Check obstacles between new position and previous position if (m_CurrentLine.lineRenderer.positionCount > 0) { //Vector3 direction = newPosition - m_CurrentLine.lineRenderer.GetPosition(m_CurrentLine.lineRenderer.positionCount - 1); if (Physics.Linecast(m_CurrentLine.lineRenderer.GetPosition(m_CurrentLine.lineRenderer.positionCount - 1), newPosition, undrawableLayerMask.value)) { return; } } m_CurrentLine.AddDrawingPoint(newPosition); } }