private void movement() { float inputX = Input.GetAxis("Horizontal"); float inputY = Input.GetAxis("Vertical"); Vector2 currentPos = rbody.position; Vector2 inputVector = new Vector2(inputX, inputY); //inputVector = Vector2.ClampMagnitude(inputVector, 1); Vector2 movement = inputVector * speed; Vector2 newPos = currentPos + movement * Time.fixedDeltaTime; rbody.MovePosition(newPos); //Get Current Run and Current Idle CurrentRun = gameObject.GetComponent <DirectionMovement>().CurrentDir; currentIdle = gameObject.GetComponent <DirectionMovement>().lastIdle; //Play animations depends if the character moves or not if (currentPos.Equals(newPos)) { animator.Play(currentIdle.ToString()); } else { //Set Direction and play CurrentRun = CurrentViewFromCroshair(); //TODO - Need to Set new last idle animator.Play(CurrentRun.ToString()); } }
/** * Pas parametres first movement */ private IEnumerator RunInControl(Animator playerAnim, SpriteRenderer key, RunDirections run, RunDirections idle, float time) { if (!panelControl.activeSelf) { yield break; } key.color = KeyCapPulsed; playerAnim.Play(run.ToString()); yield return(new WaitForSeconds(time)); if (!panelControl.activeSelf) { yield break; } key.color = KeyCapNoPulsed; playerAnim.Play(idle.ToString()); switch (knowWhatIsNext(run)) { case 1: StartCoroutine(RunInControl(playerW, keyW, RunDirections.RunN, RunDirections.IdleN, timeRun)); break; case 2: StartCoroutine(RunInControl(playerD, keyD, RunDirections.RunE, RunDirections.IdleE, timeRun)); break; case 3: StartCoroutine(RunInControl(playerS, keyS, RunDirections.RunS, RunDirections.IdleS, timeRun)); break; case 4: StartCoroutine(RunInControl(playerA, keyA, RunDirections.RunW, RunDirections.IdleW, timeRun)); break; } }