public IEnumerator DragNDropRoutine(int pointerID = -1) { GameControl.SelectTower(this); yield return(null); Vector3 cursorPos = Vector3.zero; TDTK.OnDragNDrop(true); inDragNDropRoutine = true; while (inDragNDropRoutine) { if (Input.GetKeyDown(KeyCode.Escape)) { break; } bool invalidCursor = false; if (pointerID < 0) { cursorPos = Input.mousePosition; } else { cursorPos = TDTK.GetTouchPosition(pointerID); } if (cursorPos.magnitude < 0) { invalidCursor = true; } BuildInfo buildInfo = null; if (!invalidCursor) { buildInfo = BuildManager.CheckBuildPoint(cursorPos, prefabID); if (buildInfo.status == _TileStatus.NoPlatform) { Ray ray = Camera.main.ScreenPointToRay(cursorPos); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { thisT.position = hit.point; } else { thisT.position = ray.GetPoint(30); //this there is no collier, randomly place it 30unit from camera } } else { thisT.position = buildInfo.position; thisT.rotation = buildInfo.platform.thisT.rotation; } IndicatorControl.SetBuildTileIndicator(buildInfo); } bool cursorOnUI = UI.IsCursorOnUI(pointerID); if (pointerID < 0) { if (Input.GetMouseButtonDown(0)) { if (cursorOnUI) { break; } string exception = BuildManager._BuildTower(srcTower, buildInfo); if (exception != "") { TDTK.OnGameMessage(exception); } break; } if (Input.GetMouseButtonDown(1)) { break; } } else { if (TDTK.IsTouchEnding(pointerID)) { if (cursorOnUI) { break; } string exception = BuildManager._BuildTower(srcTower, buildInfo); if (exception != "") { TDTK.OnGameMessage(exception); } break; } } yield return(null); } inDragNDropRoutine = false; TDTK.OnDragNDrop(false); IndicatorControl.SetDragNDropPhase(false); thisObj.SetActive(false); }