Question by
melandalin · Sep 08, 2020 at 08:26 AM ·
uiplayercanvasrestart game
Player not moving after pressing restart button
Hi, I am having trouble getting my restart button to work completely. When I press the button (with quitGame() selected for the button in the inspector), the Title canvas reappears which is what I want to happen, but when I click on my "Start" button, the enemies start moving in the scene but I am unable to move the player with my key input. Also the audio attached to the enemies does not play.
Here is my UI controller which is contained in my playerHealth script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.EventSystems;
[RequireComponent(typeof(CanvasManager))]
public class PlayerHealth : Destructable
{
[SerializeField] Animator animator;
public Transform mainCamera;
private GameObject player;
public TextMeshProUGUI gameOverText;
public RawImage backDrop;
public Button restartButton;
public bool isGameActive;
public Button button;
public GameObject titleScreen;
public GameObject gameOverScreen;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
button = GetComponent<Button>();
}
public override void Die()
{
base.Die();
animator.SetBool("IsDying", true);
print("Player died");
gameOverScreen.gameObject.SetActive(true);
}
public void StartGame()
{
isGameActive = true;
backDrop.gameObject.SetActive(false);
titleScreen.gameObject.SetActive(false);
}
public void quitGame()
{
Application.Quit();
print("game quitted");
isGameActive = false;
}
public void RestartGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
Comment
Your answer
Follow this Question
Related Questions
Why canvas is so big? 0 Answers
Unable to make animations for UI Image 2 Answers
Need help with death screen 1 Answer
Text in UI disappears when clicked on 0 Answers