/// <summary> /// This function removes the enemy and starts the teleport particle system and sound effect /// </summary> public void Finish() { // If not in the world, instantiate if (_teleportEffectInstance == null) { _teleportEffectInstance = Instantiate(TeleportEffect, transform.position, new Quaternion()); } // Play effect _teleportEffectInstance.Play(); // Play sound effect SoundUtil.PlayClipAtPointWithRandomPitch(TeleportSound, this.gameObject.transform.position, 0.5f, 1.5f); // Destroy after particle (emit) duration + maximum particle lifetime Destroy( _teleportEffectInstance.gameObject, _teleportEffectInstance.main.duration + _teleportEffectInstance.main.startLifetime.constantMax ); // Damage player var playerStatistics = Player.instance?.gameObject?.GetComponent <PlayerStatistics>(); if (playerStatistics != null) { playerStatistics.Lives--; } // Teleport enemy Destroy(gameObject); }
/// <summary> /// When the credit touches the hand, the credit gets added to the players total credit count /// </summary> /// <param name="hand"></param> private void OnHandHoverBegin(Hand hand) { var platerStatistics = Player.instance.gameObject.GetComponent <PlayerStatistics>(); if (platerStatistics == null) { return; } platerStatistics.Credits += Value; SoundUtil.PlayClipAtPointWithRandomPitch( PickupSound, gameObject.transform.position, PitchRange.Item1, PitchRange.Item2 ); Destroy(gameObject); }
/// <summary> /// This function kills the enemy and starts the explosion particle system and sound effect /// </summary> public void Explode() { // If not in the world, instantiate if (_explodeEffectInstance == null) { _explodeEffectInstance = Instantiate( ExplodeEffect, transform.position, new Quaternion() ); } // Play effect _explodeEffectInstance.Play(); // Play sound effect SoundUtil.PlayClipAtPointWithRandomPitch(ExplodeSound, this.gameObject.transform.position, 0.5f, 1.5f); // Destroy after particle (emit) duration + maximum particle lifetime Destroy( _explodeEffectInstance.gameObject, _explodeEffectInstance.main.duration + _explodeEffectInstance.main.startLifetime.constantMax ); // Kill enemy (if Explode() called when the enemy was still alive) Destroy(gameObject); // Spawn Credit Credit.Value = CreditValue; Instantiate( Credit, gameObject.transform.position, gameObject.transform.rotation ); GameObject.Find("Scoreboard")?.GetComponent <Scoreboard>()?.PointGain(PointValue); }