Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

28. How to make a 2D Platformer - UPGRADE 2.0 - Unity Tutorial

On this video we are using for class. When my student enters in the correct scripting for the Gamemaster script with no errors, when he hits U to toggle the Upgrade Menu nothing happens. He has his menu setup correct and his script is correct...no errors, just not bringing up the Upgrade menu when he hits U. Happens on play in unity and the build.

Any suggestions? Thanks.


using UnityEngine;

using System.Collections;

using UnityStandardAssets._2D;

//using UnityStandardAssets.ImageEffects;


public class GameMaster : MonoBehaviour

{


  public static GameMaster gm;


  [SerializeField]

  private int maxLives = 3;

  private static int _remainingLives = 3;

  public static int RemainingLives

  {

    get { return _remainingLives; }

  }


  void Awake()

  {

    if (gm == null)

    {

      gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();

    }

  }


  


  public Transform playerPrefab;

  public Transform spawnPoint;

  public float spawnDelay = 2;

  public Transform spawnPrefab;

  public string respawnCountdownSoundName = "RespawnCountdown" ;

  public string spawnSoundName = "Spawn";


  public string gameOverSoundName = "GameOver";



  public CameraShake cameraShake;


  [SerializeField]

  private GameObject gameOverUI;


  [SerializeField]

  private GameObject upgradeMenu;


  public delegate void UpgradeMenuCallback(bool active);

  public UpgradeMenuCallback onToggleUpgradeMenu;


  //cache

  private AudioManager audioManager;


  void Start()

  {

    if (cameraShake == null)

    {

      Debug.LogError("No camera shake referenced in GameMaster");

    }

    _remainingLives = maxLives;


    //caching

    audioManager = AudioManager.instance;

    if (audioManager == null)

    {

      Debug.LogError("No AudioManager found");

    }


  }


  void Update()

  {

    if (Input.GetKeyDown(KeyCode.U))

    {

      ToggleUpgradeMenu();

    }

  }


  private void ToggleUpgradeMenu()

  {

    upgradeMenu.SetActive(!upgradeMenu.activeSelf);

    onToggleUpgradeMenu.Invoke(upgradeMenu.activeSelf);

  }


  public void EndGame()

  {

    audioManager.PlaySound(gameOverSoundName);


    Debug.Log("GAME OVER");

    gameOverUI.SetActive(true);

  }


  public IEnumerator _RespawnPlayer()

  {

    audioManager.PlaySound(respawnCountdownSoundName);

    yield return new WaitForSeconds(spawnDelay);


    audioManager.PlaySound(spawnSoundName);

    Transform clone = Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation) as Transform;

    Destroy(clone, 3f);

  }


  public static void KillPlayer(Player player)

  {

    Destroy(player.gameObject);

    _remainingLives -= 1;

    if (_remainingLives <= 0)

    {

      gm.EndGame();

    }

    else

    {

      gm.StartCoroutine(gm._RespawnPlayer());

    }

  }


  public static void KillEnemy(Enemy enemy)

  {

    gm._KillEnemy(enemy);

  }

  public void _KillEnemy(Enemy _enemy)

  {

    Transform _clone = Instantiate(_enemy.deathParticles, _enemy.transform.position, Quaternion.identity) as Transform;

    Destroy(_clone.gameObject, 5f);

    cameraShake.Shake(_enemy.shakeAmt, _enemy.shakeLength);

    Destroy(_enemy.gameObject);


  }


}

Sign In or Register to comment.