private void UpdateDisplay() { if (qte == null) { return; } // Checks if the QTE is done qte.Do(); if (qte.IsDone()) { Hide(); return; } combos.text = ""; if (qte is ComboAction) { ComboAction comboAction = (ComboAction)qte; foreach (string s in comboAction.expectedCombos) { combos.text += s + " "; } combos.text = combos.text.Remove(combos.text.Length - 1); } slider.transform.localScale = new Vector3(1, 1, 1); slider.value = qte.progression; }
// Update is called once per frame void Update() { if (UIManager.Instance.HasEnded) { return; } SpriteRenderer[] renderers = GetComponentsInChildren <SpriteRenderer>(); renderers[0].sortingOrder = Mathf.RoundToInt(transform.position.y * 100f) * -1; renderers[1].sortingOrder = renderers[0].sortingOrder + 1; if (currentAction != null) { if (InputManager.GetButton(currentAction.button)) { currentAction.Do(); updatePopup(currentAction); } else { currentAction = null; } } // On déplace le joueur (utilisation du GetAxisRaw pour avoir des entrées non lissées pour plus de réactivité) input = Vector2.zero; if (currentAction == null && !IsDashing()) { input = new Vector2(InputManager.GetAxis(Axis.Horizontal), InputManager.GetAxis(Axis.Vertical)); if (input.magnitude > 1) { input.Normalize(); } if (input != Vector2.zero && InputManager.GetButtonDown(Button.Y)) { dashTimeRemaining = 0.10f; } } if (input != Vector2.zero) { direction = input; } if (IsDashing()) { input = direction * 2.5f; dashTimeRemaining -= Time.deltaTime; } _animator.SetBool("IsWalking", input.magnitude > .1f); _animator.SetBool("Walk_back", InputManager.GetAxis(Axis.Vertical) > .2f); _animator.SetBool("Walk_front", InputManager.GetAxis(Axis.Vertical) < -.2f); _animator.SetBool("Walk_right", InputManager.GetAxis(Axis.Horizontal) > .2f); _animator.SetBool("Walk_left", InputManager.GetAxis(Axis.Horizontal) < -.2f); _animator.speed = input.magnitude > .1f ? 1 : input.magnitude; if (currentAction == null) { if (inRange.Count > 0) { // On cherche l'objet intéractif le plus proche avec la meilleure action UserAction bestAction = null; float distanceMin = float.PositiveInfinity; GameObject nearest = null; foreach (GameObject o in inRange) { UserAction action = o.GetComponent <Interactive>().GetAction(this); float distance = (o.transform.position - transform.position).magnitude; if (action != null) { if (bestAction == null || bestAction.priority < action.priority || (bestAction.priority == action.priority && distance < distanceMin)) { bestAction = action; distanceMin = distance; nearest = o; } } else if (bestAction == null && distance < distanceMin) { distanceMin = distance; nearest = o; } } // On désélectionne l'objet sélectionné auparavant if (selected != null) { selected.GetComponent <Interactive>().Deselect(); } selected = nearest; Interactive interactive = selected.GetComponent <Interactive>(); // On le sélectionne (mise en surbrillance) interactive.Select(); if (bestAction != null && !IsDashing() && InputManager.GetButtonDown(bestAction.button)) { currentAction = bestAction; currentAction.Do(); if (currentAction.IsDone()) { currentAction = null; } } updatePopup(bestAction); } else { updatePopup(null); _spriteRenderer.color = Color.white; if (selected != null) { selected.GetComponent <Interactive>().Deselect(); selected = null; } } } // TODO : changer le bouton pour poser le seau if (InputManager.GetButtonDown(Button.B)) { DropBucket(); } }