// Update is called once per frame void Update() { if (moving != null) { Vector2 dir = ((Vector2)Input.mousePosition - mouseStart); Vector2 nDir = dir.normalized; Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); newIndex = Point.clone(moving.index); Point add = Point.zero; if (dir.magnitude > 32) //마우스가 32픽셀 넘어가 잇을경우 //(1,0) or (-1,0 ) (0,1 ) (0,-1) { if (aDir.x > aDir.y) { add = (new Point((nDir.x > 0) ? 1 : -1, 0)); } else if (aDir.y > aDir.x) { add = (new Point(0, (nDir.y > 0) ? -1 : 1)); //y좌표가 위로 가면(0보다크면) 아래에 잇는 모양이랑 바뀌어야하니까 위로갓을때 -1 } } newIndex.add(add); Vector2 pos = game.getPositionFromPoint(moving.index); if (!newIndex.Equals(moving.index)) { pos += Point.mult(new Point(add.x, -add.y), 16).ToVector(); } moving.MovePositionTo(pos); } }
void Update() { if (moving != null) { Vector2 dir = ((Vector2)Input.mousePosition - mouseStart); Vector2 nDir = dir.normalized; Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); // absolute direction newIndex = Point.clone(moving.index); Point add = Point.zero; if (dir.magnitude > 32) // jezeli myszka jest odallona od 32px od pozycji startowej { // make add either (1,0) | (-1, 0) | (0, 1) | (0, -1) depending on the direction of the mouse point if (aDir.x > aDir.y) { add = (new Point((nDir.x > 0) ? 1 : -1, 0)); } else if (aDir.y > aDir.x) { add = (new Point(0, (nDir.y > 0) ? -1 : 1)); } } newIndex.add(add); Vector2 pos = game.getPositionFromPoint(moving.index); if (!newIndex.Equals(moving.index)) { pos += Point.mult(new Point(add.x, -add.y), 16).ToVector(); } moving.MovePositionTo(pos); } }
void Update() { if (moving != null) { Vector2 dir = ((Vector2)Input.mousePosition - mouseStart); Vector2 nDir = dir.normalized; Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); newIndex = Point.clone(moving.index); Point add = Point.zero; if (dir.magnitude > 34) //If our mouse is 34 pixels away from the starting point of the mouse { //Make add either (1,0) | (-1,0) | (0,1) | (0.-1) depending on the direction of the mouse point if (aDir.x > aDir.y) { add = (new Point((nDir.x > 0) ? 1 : -1, 0)); } else if (aDir.y > aDir.x) { add = (new Point(0, (nDir.y > 0) ? -1 : 1)); } } newIndex.add(add); Vector2 pos = game.getPositionFromPoint(moving.index); if (!newIndex.Equals(moving.index)) { pos += Point.mult(new Point(add.x, -add.y), 16).ToVector(); } moving.MovePositionTo(pos); } }
void Update() { if (moving != null) { Vector2 dir = (Vector2)Input.mousePosition - mouseStart; Vector2 nDir = dir.normalized; Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); newIndex = Point.clone(moving.index); Point add = Point.zero; if (dir.magnitude > 32) { if (aDir.x > aDir.y) { add = new Point((nDir.x > 0) ? 1 : -1, 0); } else if (aDir.y > aDir.x) { add = new Point(0, (nDir.y > 0) ? -1 : 1); } } newIndex.add(add); Vector2 pos = game.getPositionFromPoint(moving.index); if (!newIndex.Equals(moving.index)) { pos += Point.mult(new Point(add.x, -add.y), 16).ToVector(); } moving.MovePositionTo(pos); } }
private void Update() { if (_moving != null) { Vector2 direction = (Vector2)Input.mousePosition - _mouseStart; Vector2 nDirection = direction.normalized; Vector2 aDirection = new Vector2(Mathf.Abs(direction.x), Mathf.Abs(direction.y)); _newIndex = Point.Clone(_moving.index); Point add = Point.Zero; if (direction.magnitude > -258) { if (aDirection.x > aDirection.y) { add = new Point(nDirection.x > 0 ? 1 : -1, 0); } else if (aDirection.x < aDirection.y) { add = new Point(0, nDirection.y > 0 ? -1 : 1); } } _newIndex.Add(add); Vector2 position = _game.GetPositionFromPoint(_moving.index); if (!_newIndex.Equals(_moving.index)) { position += Point.Multiply(new Point(add.x, -add.y), 16).ToVector(); } _moving.MovePositionTo(position); } }
// Update is called once per frame void Update() { if (moving != null) { Vector2 dir = ((Vector2)Input.mousePosition - mouseStart); Vector2 nDir = dir.normalized; Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); newIndex = Point.clone(moving.index); Point add = Point.zero; if (dir.magnitude > 32)// Se o mouse estiver a 32 pixels de distancia de onde começou { // Faz adicionar ou (1, 0) || (-1, 0) || (0, 1) || (0, -1) dependendo da direção do ponto do mouse if (aDir.x > aDir.y) { add = (new Point((nDir.x > 0) ? 1 : -1, 0)); } else if (aDir.y > aDir.x) { add = (new Point(0, (nDir.y > 0) ? -1 : 1)); } } newIndex.add(add); Vector2 pos = game.getPositionFromPoint(moving.index); if (!newIndex.Equals(moving.index)) { pos += Point.mult(new Point(add.x, -add.y), 16).toVector(); } moving.MovePositionTo(pos); } }
void Update() { if (moving != null) { Vector2 dir = ((Vector2)Input.mousePosition - mouseStart); Vector2 nDir = dir.normalized; Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); newIndex = Point.clone(moving.index); Point add = Point.zero; if (dir.magnitude > 50) //마우스가 시작점부터 50이상 떨어졌다면 { // if eles if 와 삼항연산자를 이용해서 4개의 경우의 수를 가려내고 if (aDir.x > aDir.y) { add = (new Point((nDir.x > 0) ? 1 : -1, 0)); } else if (aDir.y > aDir.x) { add = (new Point(0, (nDir.y > 0) ? -1 : 1)); } } newIndex.add(add); Vector2 pos = game.getPositionFromPoint(moving.index); //50만큼 이동 if (!newIndex.Equals(moving.index)) { pos += Point.mult(new Point(add.x, -add.y), 25).ToVector(); } moving.MovePositionTo(pos); } }
// Update is called once per frame void Update() { if (moving != null) { Vector2 dir = ((Vector2)Input.mousePosition - mouseStart); Vector2 nDir = dir.normalized; Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); newIndex = Point.clone(moving.index); Point add = Point.zero; if (dir.magnitude > 32) //Ha rákattintunk és 32pixellel arréb húzzuk az egerünket { if (aDir.x > aDir.y) { add = (new Point((nDir.x > 0) ? 1 : -1, 0)); } else if (aDir.y > aDir.x) { add = (new Point(0, (nDir.y > 0) ? -1 : 1)); } } newIndex.add(add); Vector2 pos = game.getPositionFromPoint(moving.index); if (!newIndex.Equals(moving.index)) // az irányába a gem egy kicsit mozduljon meg { pos += Point.mul(new Point(add.x, -add.y), 64).ToVector(); } moving.MovePositionTo(pos); } }
void Update() { if (moving != null) { #if UNITY_EDITOR Vector2 dir = ((Vector2)Input.mousePosition - mouseStart); #endif #if UNITY_ANDROID && !UNITY_EDITOR Touch touch; touch = Input.GetTouch(0); Vector2 dir = ((Vector2)touch.position - mouseStart); #endif Vector2 nDir = dir.normalized; Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); newIndex = Point.Clone(moving.index); Point add = Point.Zero; if (dir.magnitude > 32) //If our mouse is 32 pixels away from the starting point of the mouse { //make add either (1, 0) | (-1, 0) | (0, 1) | (0, -1) depending on the direction of the mouse point if (aDir.x > aDir.y) { add = (new Point((nDir.x > 0) ? 1 : -1, 0)); } else if (aDir.y > aDir.x) { add = (new Point(0, (nDir.y > 0) ? -1 : 1)); } } newIndex.Add(add); Vector2 pos = game.getPositionFromPoint(moving.index); if (!newIndex.Equals(moving.index)) { pos += Point.Mult(new Point(add.x, -add.y), 16).ToVector(); } moving.MovePositionTo(pos); } }
void Update() { if (moving != null) { Vector2 dir = ((Vector2)Input.mousePosition - mouseStart); Vector2 nDir = dir.normalized; Vector2 aDir = new Vector2(Mathf.Abs(dir.x), Mathf.Abs(dir.y)); newIndex = Point.clone(moving.index); Point add = Point.zero; if (dir.magnitude > 32) // Если наша мышка на 32 пикселя отдалилась от своего первоначального значения { // дает понять мышке координаты обьекта на котором она находится ((0,0) | (1,0) | (0,1) | (1,1) и т.д.) if (aDir.x > aDir.y) { add = (new Point((nDir.x > 0) ? 1 : -1, 0)); } else if (aDir.y > aDir.x) { add = (new Point(0, (nDir.y > 0) ? -1 : 1)); } } newIndex.x = newIndex.x + add.x; newIndex.y = newIndex.y + add.y; Vector2 pos = game.getPositionFromPoint(moving.index); if (!newIndex.Equals(moving.index)) { pos += Point.mult(new Point(add.x, -add.y), 16).ToVector(); // (16) - расстояние на которое сдвинется от начальной позиции эллемент при попытке направить его пальцем или мышкой // должна быть половина от размера эллемента } moving.MovePositionTo(pos); } }