public void updateInput() { // move left if (Input.GetKey(KeyCode.LeftArrow)) { playerVal.setDirectionalX(PlayerValues.inputState.WalkLeft); playerVal.setFacing(PlayerValues.facing.Left); timerR = -1; if (timerL == -1) { timerL = Time.time; } else if (Time.time > timerL + timeTellRun) { //run playerVal.setDirectionalX(PlayerValues.inputState.RunLeft); } } else if (Input.GetKey(KeyCode.RightArrow)) { playerVal.setDirectionalX(PlayerValues.inputState.WalkRight); playerVal.setFacing(PlayerValues.facing.Right); timerL = -1; if (timerR == -1) { timerR = Time.time; } else if (Time.time > timerR + timeTellRun) { //run playerVal.setDirectionalX(PlayerValues.inputState.RunRight); } } else { timerL = -1; timerR = -1; playerVal.setDirectionalX(PlayerValues.inputState.None); } //float or fall now is the time if (Input.GetKey(KeyCode.DownArrow)) { playerVal.setDirectionalY(PlayerValues.inputState.Fall); } else if (Input.GetKey(KeyCode.UpArrow)) { playerVal.setDirectionalY(PlayerValues.inputState.Float); } else { playerVal.setDirectionalY(PlayerValues.inputState.None); } // jump if (Input.GetKeyDown(KeyCode.Space)) { playerVal.setJumps(PlayerValues.inputState.Jump); } else { playerVal.setJumps(PlayerValues.inputState.None); } if (Input.GetKeyDown(KeyCode.F)) { playerVal.setAttack(PlayerValues.inputState.HitMain); } else if (Input.GetKey(KeyCode.D)) { } else { playerVal.setAttack(PlayerValues.inputState.None); } }
public void updateInput() { attack = PlayerValues.inputState.None; middle = Screen.currentResolution.width / 2; r = 0; l = 0; foreach (Touch tut in Input.touches) { float x = tut.position.x; bool isRight = x > middle; if (isRight) { r++; if (initRight) { if (Right.fingerId == tut.fingerId) { Right = tut; TouchPhase phase = Right.phase; //could be a swipe!!! if (phase == TouchPhase.Canceled || phase == TouchPhase.Ended) { float swipeTime = Time.time - rstartTime; float swipeDist = (Right.position.y - RightStart.y); //calculateSwipeVals( swipeDist, swipeTime); if (swipeTime > minSwipeTime && swipeTime < maxSwipeTime && swipeDist > minSwipeDist && swipeDist < maxSwipeDist) { playerVal.setJumps(PlayerValues.inputState.Jump); attack = PlayerValues.inputState.None; } else { attack = PlayerValues.inputState.HitMain; playerVal.setJumps(PlayerValues.inputState.None); } } //TODO check for holding for shield } else if (initLeft && Left.fingerId == tut.fingerId) { endLeft(); } else { //drop this toutch it is an extra one we don't care about } } else if (!(initLeft && Left.fingerId == tut.fingerId)) { Right = tut; initRight = true; RightStart = Right.position; rstartTime = Time.time; } else { endLeft(); } } else { l++; if (initLeft) { if (Left.fingerId == tut.fingerId) { Left = tut; float ldeltx = Left.position.x - LeftStart.x; float ldelty = Left.position.y - LeftStart.y; float dist = Mathf.Abs(Vector2.Distance(Left.position, LeftStart)); if (dist > nullarea) { if (ldeltx < -nullarea) { playerVal.setDirectionalX(PlayerValues.inputState.WalkLeft); playerVal.setFacing(PlayerValues.facing.Left); } else if (ldeltx > nullarea) { playerVal.setFacing(PlayerValues.facing.Right); playerVal.setDirectionalX(PlayerValues.inputState.WalkRight); } if (ldelty > nullarea) { playerVal.setDirectionalY(PlayerValues.inputState.Float); } else if (ldelty < -nullarea) { playerVal.setDirectionalY(PlayerValues.inputState.Fall); } } else { playerVal.setDirectionalX(PlayerValues.inputState.None); playerVal.setDirectionalY(PlayerValues.inputState.None); } } else if (!(initRight && Right.fingerId == tut.fingerId)) { endRight(); } else { //drop this toutch it is an extra one we don't care about } } else if (!(initRight && Right.fingerId == tut.fingerId)) { Left = tut; initLeft = true; LeftStart = Left.position; } else { endRight(); } } } if (l == 0 || !initLeft) { endLeft(); } if (r == 0 || !initRight) { endRight(); } playerVal.setAttack(attack); // gui.text = touchinfo; }