// Intitialize component references and singleton void Awake() { if (player == null) { player = this; } else if (player != this) { Destroy(gameObject); } DontDestroyOnLoad(player); rb = GetComponent <Rigidbody2D> (); bc = GetComponent <BoxCollider2D> (); rocket = GetComponent <RocketBoost>(); inventory = GetComponent <Inventory>(); if (inventory == null) { throw new InvalidOperationException(); } }
public PowerUp GetPowerUp() { if (powerUpID == PowerUpList.RANDOM) { Array values = Enum.GetValues(typeof(PowerUpList)); powerUpID = (PowerUpList)UnityEngine.Random.Range(0, values.Length - 1); } PowerUp chosenPowerUp = null; // Add new Powerups here (pt 2 of 2) switch (powerUpID) { case PowerUpList.RocketBoost: //Debug.Log("Chose the Debug PowerUp!"); chosenPowerUp = new RocketBoost(); //print("Chosen Power null? : " + (chosenPowerUp == null)); break; case PowerUpList.Brake: chosenPowerUp = new BrakePowerUp(); break; case PowerUpList.MoonJump: chosenPowerUp = new MoonJump(); break; case PowerUpList.Bomb: chosenPowerUp = new BombPowerUp(); break; case PowerUpList.GravityVortex: chosenPowerUp = new GravityVortexPowerUp(); break; } gameObject.GetComponent <MeshRenderer>().enabled = false; gameObject.GetComponent <Collider>().enabled = false; spawned = false; turnsInactive = 0; return(chosenPowerUp); }