private void SetTargetPoint() { // Generate a plane that intersects the transform's position with an upwards normal. Plane playerPlane = new Plane(Vector3.back, new Vector3(0, 0, 0)); //transform.position + // Generate a ray from the cursor position Ray RayCast; if (Input.touchCount > 0) { RayCast = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); } else { RayCast = Camera.main.ScreenPointToRay(Input.mousePosition); } // Determine the point where the cursor ray intersects the plane. float HitDist = 0; // If the ray is parallel to the plane, Raycast will return false. if (playerPlane.Raycast(RayCast, out HitDist)) //playerPlane.Raycast { // Get the point along the ray that hits the calculated distance. Vector3 RayHitPoint = RayCast.GetPoint(HitDist); transform.position = new Vector3(RayHitPoint.x, RayHitPoint.y, targetZ); } }
//this is called by 4 invisible tk2d buttons on the edge of the screen //Anchor/ center/ UnitsBattle/ deploypad private void RecordSpawnPoint() { if (!((Helios)helios).networkLoadReady || ((Relay)relay).delay) { return; } if (deploying) { ((Messenger)heliosMsg).DisplayMessage("Deployment in progress. Please wait."); return; } Vector3 gridPos = new Vector3(0, 0, 0); // Generate a plane that intersects the transform's position with an upwards normal. Plane playerPlane = new Plane(Vector3.back, new Vector3(0, 0, 0)); //transform.position + // Generate a ray from the cursor position Ray RayCast; if (Input.touchCount > 0) { RayCast = mainCamera.ScreenPointToRay(Input.GetTouch(0).position); } else { RayCast = mainCamera.ScreenPointToRay(Input.mousePosition); // Camera.main. } // Determine the point where the cursor ray intersects the plane. float HitDist = 0; // If the ray is parallel to the plane, Raycast will return false. if (playerPlane.Raycast(RayCast, out HitDist)) //playerPlane.Raycast { // Get the point along the ray that hits the calculated distance. Vector3 RayHitPoint = RayCast.GetPoint(HitDist); int indexCell = GridManager.instance.GetGridIndex(RayHitPoint); int col = GridManager.instance.GetColumn(indexCell); int row = GridManager.instance.GetRow(indexCell); if (row > 0 && row < 34 && col > 0 && col < 34) //force click inside map { if (!GridManager.instance.nodes[row, col].isObstacle) { gridPos = GridManager.instance.nodes[row, col].position; CreateStar(gridPos); } } } }