Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

[Bug] Player não se mexendo

Após o player morrer e pressionarmos o botão de restart, aparece, por um instante, a tela de pause. Após isso, ela fecha e o jogo começa. Porém, ao invés de tudo ficar normal, o player fica travado. Você consegue apertar as teclas para ele se mexer — ele faz até o som de andar/pular e até as animações — mas não sai do lugar.

public class UIManager : MonoBehaviour
{
    [Header("Text")]
    [SerializeField] private TextMeshProUGUI KeysText;
    [SerializeField] private TextMeshProUGUI LifeText;

    [Header("Panels")]
    [SerializeField] private GameObject optionsPanel;
    [SerializeField] private GameObject PausePanel;
    [SerializeField] private GameObject GameOverPanel;

    private void Awake()
    {
        PausePanel.SetActive(false);
        optionsPanel.SetActive(false);
        GameOverPanel.SetActive(false);
    }

    private void Start()
    {
        GameManager.Instance.InputManager.OnPause += OpenClosePauseMenu;
        
    }

    public void OpenClosePauseMenu()
    {
        if (PausePanel.activeSelf == false)
        {
            Time.timeScale = 0f;
            GameManager.Instance.InputManager.DisablePlayerInput();
            PausePanel.SetActive(true);
        }
        else
        {
            Time.timeScale = 1f;
            GameManager.Instance.InputManager.EnablePlayerInput();
            PausePanel.SetActive(false);
        }
    }

    public void OpenOptionsPanel()
    {
        print("Set options to be opened");
        optionsPanel.SetActive(true);
    }

    public void OpenGameOverPanel()
    {
        GameOverPanel.SetActive(true);
    }
    public void UpdateKeysLeftText(int totalValue, int LeftValue)
    {
        KeysText.text = $"Keys: {LeftValue}/{totalValue}";
    }

    public void UpdateLivesText(int amount)
    {
        LifeText.text = $"{amount}";
    }
}
public class GameOverUI : MonoBehaviour
{
    [SerializeField] private Button restartButton;
    [SerializeField] private Button menuButton;

    private void Awake()
    {
        restartButton.onClick.AddListener(RestartGame);
        menuButton.onClick.AddListener(ReturnToMenu);
    }

    private void ReturnToMenu()
    {
       SceneManager.LoadScene("MainMenu");
    }

    private void RestartGame()
    {
        SceneManager.LoadScene("Gameplay");
    }
}
public class GameManager : MonoBehaviour
{

    public static GameManager Instance { get; private set; }
    public InputManager InputManager { get; private set; }

    [Header("Managers")]
    public UIManager UIManager;
    public AudioManager AudioManager;

    [Header("DynamicGameobject")]
    [SerializeField] private GameObject BossDoor;
    [SerializeField] private PlayerBehavior Player;
    [SerializeField] private BossBehavior boss;
    [SerializeField] private BossFightTrigger bossFightTrigger;

    private int totalKeys;
    private int LeftcollectedKeys;

    [System.Obsolete]
    private void Awake()
    {
        if (Instance != null)
        {
            Destroy(this.gameObject);
            
        }
        Instance = this;

        totalKeys = FindObjectsOfType<CollectableKey>().Length;
        LeftcollectedKeys = totalKeys;

        InputManager = new InputManager();
        UIManager.UpdateKeysLeftText(totalKeys, LeftcollectedKeys);

        bossFightTrigger.OnPlayerEnterBossFight += ActivateBossBehavior;

        Player.GetComponent<Health>().OnDead += HandleGameOver;
    }
   public void UpdateKeysLeft()
    {
        LeftcollectedKeys--;
        UIManager.UpdateKeysLeftText(totalKeys, LeftcollectedKeys);
        CheckAllKeysCollected();
    }
    private void CheckAllKeysCollected()
    {
        if (LeftcollectedKeys <= 0)
        {
           Destroy(BossDoor);
        }
    }

    private void ActivateBossBehavior()
    {
        boss.StartChasing();
    }

    private void HandleGameOver()
    {
       UIManager.OpenGameOverPanel();
    }
2 respostas
solução!

Oi, Kaio! Como vai?

Pelo que você descreveu, as animações e sons são acionados, mas o player permanece no mesmo lugar. Isso pode ser causado por algumas razões comuns. Vou sugerir algumas verificações e soluções que podem ajudar:

  1. Verifique o Time.timeScale: Certifique-se de que o Time.timeScale está definido como 1f após reiniciar o jogo. Se o tempo ainda estiver pausado (Time.timeScale = 0f), isso poderia impedir o movimento do player.

    private void RestartGame()
    {
        Time.timeScale = 1f; // Certifique-se de que o tempo está normal
        SceneManager.LoadScene("Gameplay");
    }
    
  2. Reinicialize o InputManager: Após reiniciar a cena, o InputManager deve estar habilitado para permitir a entrada do jogador. Verifique se o método EnablePlayerInput() está sendo chamado corretamente após o reinício.

  3. Verifique a posição inicial do player: Certifique-se de que o player está sendo reposicionado corretamente na cena quando o jogo é reiniciado. Pode ser útil adicionar um log para verificar a posição do player após o reinício.

  4. Problemas com Física: Se o player usa um componente de física como Rigidbody, certifique-se de que ele não está em um estado que impeça o movimento, como estar preso em um objeto ou ter a velocidade zerada.

Espero que essas dicas ajudem a resolver o problema que você está enfrentando. Bons estudos!

Caso este post tenha lhe ajudado, por favor, marcar como solucionado ✓.

Boa tarde professor, o problema era o Time agradeço pela ajuda