private void OnTriggerEnter2D(Collider2D hitInfo) { PlayerHealth player = hitInfo.GetComponent <PlayerHealth>(); if (player) { player.AddShield(); Destroy(gameObject); } }
IEnumerator AddShield(int shieldType, float delay) { yield return(new WaitForSeconds(delay)); _health.AddShield(shieldType); if (shieldType == 0) { anim.ObjectSoundSource.PlayOneShot(anim.GetSoundFromBank("Shield", anim.ObjectSounds)); } }
private void OnTriggerEnter(Collider other) { if (other.tag == "Player") { PlayerHealth playerHealth = other.gameObject.GetComponent <PlayerHealth>(); // If the player has health to lose... if (playerHealth.currentHealth > 0) { playerHealth.AddShield(timeToShield); } Destroy(gameObject); } }