public void OnEnemyHitEffect(OnEnemyHit.HitDetails details) { // Prevent multiple hits at the same time. if (Time.time - lastEnemyHitTime > stats.TIME_BETWEEN_ENEMY_HIT && stats.status != CharacterDefinitions.CharacterStats.StatusTypes.dead) { // Play hit sound. GameObject globalSound = (GameObject)Instantiate(Resources.Load("GlobalSoundSource")); GlobalSoundPlay soundScript = globalSound.GetComponent <GlobalSoundPlay>(); soundScript.playGlobalSound(details.hitSfx, 0.4f); lastEnemyHitTime = Time.time; hCUI.consumeHp(20); if (hCUI.currentHp <= 0) { resetAnimationStatus(); stats.status = CharacterDefinitions.CharacterStats.StatusTypes.dead; animator.SetBool("DieBack", true); GlobalEvents geScript = gameController.GetComponent <GlobalEvents>(); geScript.showGameOverScreen(); } else { stats.status = CharacterDefinitions.CharacterStats.StatusTypes.injured; Invoke("hitAnimationToNormal", stats.TIME_WITH_HIT_EXPRESSION); } } }
private void continousHitSignal() { OnEnemyHit.HitDetails hitDetails = new OnEnemyHit.HitDetails(); hitDetails.damageAmount = damageAmount; hitDetails.hitPoint = transform.position; hitDetails.hitSfx = hitSoundEffect; OnEnemyHit oehScript = player.GetComponent <OnEnemyHit>(); oehScript.triggerDelegate(hitDetails); }
public void OnTriggerStay2D(Collider2D collision) { // Check if we collided with the player. if (collision.gameObject == player && stats.status != EnemyStatus.StatusType.bouncing) { rb.velocity = Vector2.zero; stats.status = EnemyStatus.StatusType.bouncing; //Send the hit signal. OnEnemyHit.HitDetails hitDetails = new OnEnemyHit.HitDetails(); hitDetails.damageAmount = damageAmount; hitDetails.hitPoint = transform.position; hitDetails.hitSfx = hitSoundEffect; OnEnemyHit oehScript = player.GetComponent <OnEnemyHit>(); oehScript.triggerDelegate(hitDetails); BounceBack(); } }