public void removeExtraLife() { if (_numExtraLives == 0) // avoid empty stack error { Debug.Log("Already have zero lives!"); return; } ExtraLife removedLife = ExtraLives.Pop(); // remove the top-most ExtraLife on the stack respawnSound.Play(); Destroy(removedLife.ExtraLifeIcon); // destroy the GameObject pertaining to the ExtraLife removedLife.ExtraLifeIcon = null; // set previous members to null _numExtraLives--; // decrement number for correct visual stacking on UI }
public void addExtraLife() { if (_numExtraLives == maxExtraLives) { Debug.Log("Maximum number of lives reached"); return; } ExtraLife newLife = new ExtraLife(); // create new ExtraLife item for stack newLife.pos = (_numExtraLives * iconGaps); // assign position relative to how many lives are on stack currently newLife.ExtraLifeIcon = Instantiate <GameObject>(ExtraLifeIcon); // instantiate prefab newLife.ExtraLifeIcon.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false); // move it under canvas so it displays properly newLife.ExtraLifeIcon.transform.Translate(0, newLife.pos, 0); // translate prefab to correct position ExtraLives.Push(newLife); // push onto stack _numExtraLives++; // increment number for correct visual stacking on UI through relative positioning Debug.Log("Attempted to add extra life"); }
/// <summary> /// Unpack an interactable /// </summary> /// <param name="d"></param> /// <returns></returns> public Interactable Unpack(InteractableData d) { var tex = content.Load <Texture2D>(itemFilePath + d.textureName); Sprite sprite = new Sprite(tex, Utils.scaleForTexture(tex), Color.White); Interactable newInteractable; if (d is PowerupData p) { //Powerups are a very simple subclass of interactables, //they need no extra handling except their one piece of data var newPowerup = new Powerup(sprite, Vector2.Zero); newPowerup.powerupType = p.powerupType; newInteractable = newPowerup; } else { switch (d.interactableType) { case InteractableType.coin: newInteractable = new Coin(sprite, Vector2.Zero); break; case InteractableType.nextLevel: newInteractable = new LevelTransition(sprite, Vector2.Zero); break; case InteractableType.extraLife: newInteractable = new ExtraLife(sprite, Vector2.Zero); break; default: newInteractable = null; break; } } return(newInteractable); }
public void ShouldBeCorrectTypeWhenCreated() { extraLife = new ExtraLife((new Server.GameObject(new Server.Coordinates()))); Assert.AreEqual(TileEnumerator.TileTypeEnum.PUExtraLife, extraLife.type); }
private void HandleDeath() { // If this is the player, they have an extra life equipped, and it hasn't been used, SURVIVE! if (GetComponent <PlayerController>() != null) { if (Game.instance.playerStats.IsItemEquipped <ExtraLife>()) { ExtraLife el = Game.instance.playerStats.GetComponentInChildren <ExtraLife>(); if (!el.used) { el.used = true; health = 50; Game.instance.playerData.health = health; Game.instance.playerData.MarkDirty(); return; } } } isDead = true; if (onDeath != null) { onDeath(this); } if (deathResponse == DeathResponse.Destroy) { float destroyTime = 2f; if (deathEffect == "CFX2_EnemyDeathSkull" && Game.instance.quirkRegistry.IsQuirkActive <GothQuirk>()) { deathEffect = "CFX2_BatsCloud"; destroyTime = 5f; } GameObject vfx = PrefabManager.instance.InstantiatePrefabByName(deathEffect); vfx.transform.position = transform.position + Vector3.up * 0.5f; vfx.transform.localScale = Vector3.one * deathEffectScale; vfx.AddComponent <DestroyAfterTimeElapsed>().time = destroyTime; Destroy(gameObject); } else { if (deathResponse != DeathResponse.MakeInactiveSilent) { GameObject vfx = PrefabManager.instance.InstantiatePrefabByName("CFX2_BrokenHeart"); vfx.transform.position = transform.position + Vector3.up * 0.5f; if (mEnemy && mEnemy.isBoss) { mMovement.mesh.transform.DOLocalMoveY(deathAdjustment, 1f).SetDelay(2f); } } else { mMovement.mesh.transform.DOLocalMoveY(-0.15f, 1f).SetDelay(2f); } if (mEnemy) { GetComponentInChildren <Animator>().Play("Death"); } } }