public void EndDrag(Vector2 posTouch) { CameraControl.instance.inMovement = true; if (posTouch.y < 200) { Destroy(currentUnity); currentUnity = null; currentController = null; //currentUnityMaterial = null; } else { Vector3 pos = mainCamera.ScreenToWorldPoint(new Vector3(posTouch.x, posTouch.y, 5)); dir = pos - mainCamera.transform.position; RaycastHit hitInfo; int layerMask = 1 << 8; layerMask = ~layerMask; if (Physics.Raycast(mainCamera.transform.position, dir, out hitInfo, 20, layerMask)) { //Debug.Log(hitInfo.collider.name + ", " + hitInfo.collider.tag + " . " + hitInfo.point); currentUnity.transform.position = new Vector3(hitInfo.point.x, 0.5f, hitInfo.point.z); NavMeshHit hitNav; bool b1 = UnitiesManager.instance.CheckPosition(hitInfo.point); bool b2 = NavMesh.SamplePosition(hitInfo.point, out hitNav, 0.5f, NavMesh.AllAreas); //Debug.Log(b1+" . "+ b2); if (b1 && b2) { //currentUnityMaterial.color = initialColor; currentController.SetColor(initialColor); UnitiesManager.instance.AddUnity(currentUnity, typeId); currentUnity = null; currentUnityMaterial = null; } else { Destroy(currentUnity); currentUnity = null; currentController = null; //currentUnityMaterial = null; } } } UIController.instance.ClearUnitData(); }