void HandleInput() { if (Time.time < _protectInputTime) { return; } if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) { Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition; if (touchDeltaPosition.magnitude < 10.0f) { return; } Debug.Log(touchDeltaPosition); if (Mathf.Abs(touchDeltaPosition.x) > Mathf.Abs(touchDeltaPosition.y)) { if (touchDeltaPosition.x > 0) { Vector2 temptouchpos = new Vector2(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y); Vector3 worldpos = Camera.main.ScreenToWorldPoint(temptouchpos); _moveTouchPos = temptouchpos; _moveWorldPos = worldpos; _curState.handleInput(BaseGameState.GameInputEvent.MoveRight, (int)getPosInArry(new Vector2(worldpos.x, worldpos.y)).y); } else { Vector2 temptouchpos = new Vector2(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y); Vector3 worldpos = Camera.main.ScreenToWorldPoint(temptouchpos); _moveTouchPos = temptouchpos; _moveWorldPos = worldpos; _curState.handleInput(BaseGameState.GameInputEvent.MoveLeft, (int)getPosInArry(new Vector2(worldpos.x, worldpos.y)).y); } } else { if (touchDeltaPosition.y > 0) { Vector2 temptouchpos = new Vector2(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y); Vector3 worldpos = Camera.main.ScreenToWorldPoint(temptouchpos); _moveTouchPos = temptouchpos; _moveWorldPos = worldpos; _curState.handleInput(BaseGameState.GameInputEvent.MoveUp, (int)getPosInArry(new Vector2(worldpos.x, worldpos.y)).x); } else { Vector2 temptouchpos = new Vector2(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y); Vector3 worldpos = Camera.main.ScreenToWorldPoint(temptouchpos); _moveTouchPos = temptouchpos; _moveWorldPos = worldpos; _curState.handleInput(BaseGameState.GameInputEvent.MoveDown, (int)getPosInArry(new Vector2(worldpos.x, worldpos.y)).x); } } } if (Input.GetKeyDown(KeyCode.A)) { _curState.handleInput(BaseGameState.GameInputEvent.MoveLeft, 0); } else if (Input.GetKeyDown(KeyCode.D)) { _curState.handleInput(BaseGameState.GameInputEvent.MoveRight, 0); } else if (Input.GetKeyDown(KeyCode.W)) { _curState.handleInput(BaseGameState.GameInputEvent.MoveUp, 0); } else if (Input.GetKeyDown(KeyCode.S)) { _curState.handleInput(BaseGameState.GameInputEvent.MoveDown, 0); } }