void EndDrag() { OnEndDrag.Invoke(); Dragging = false; FieldMapController fieldMapColtroller = FieldMap.GetComponent <FieldMapController>(); Vector2 pos = fieldMapColtroller.GetCellPosFromShipPos(transform.position); bool isValid = fieldMapColtroller.CheckValidShipPos(gameObject, pos); if (!isValid) { ResetShip(); } else { GameObject cell = fieldMapColtroller.GetCellByPos(pos); Vector3 position = new Vector3( Camera.main.WorldToScreenPoint(cell.transform.position).x, Camera.main.WorldToScreenPoint(cell.transform.position).y, ZPosition ); transform.position = Camera.main.ScreenToWorldPoint(position); fieldMapColtroller.SetShipIntoArray(gameObject); RotateButton.gameObject.SetActive(false); } fieldMapColtroller.ResetCellStatus(); SoundManager.Instance.PlaySound(SoundManager.Sound.BOAT_TO_WATER); }
private void Update() { if (Draggable) { if (Dragging) { Vector3 position = new Vector3( Input.mousePosition.x, Input.mousePosition.y, ZPosition ); transform.position = Camera.main.ScreenToWorldPoint(position); FieldMapController fieldMapColtroller = FieldMap.GetComponent <FieldMapController>(); Vector2 pos = fieldMapColtroller.GetCellPosFromShipPos(transform.position); fieldMapColtroller.CheckValidShipPos(gameObject, pos); } } }