public void TakeDamage(int damageTaken) { OnEnemyHit?.Invoke(); wasHit = true; if (GetComponent <DamageEffect>() != null) { GetComponent <DamageEffect>().Activate(); } // Display the amount of damage the player has dealt var damageNumberDisplay = Instantiate(damageNumberDisplayPrefab, transform.Find("Canvas")); // Randomly set the anchored X position var rectTransform = damageNumberDisplay.GetComponent <RectTransform>().anchoredPosition3D; rectTransform = new Vector3(Random.Range(rectTransform.x - 5f, rectTransform.x + 5f), 0f, 0f); damageNumberDisplay.GetComponent <RectTransform>().anchoredPosition3D = rectTransform; damageNumberDisplay.GetComponent <TextMeshProUGUI>().SetText($"-{damageTaken}"); // Update the damage text CurHp -= damageTaken; GameManager.Instance.playerUi.ToggleEnemyInfoPanel(true); GameManager.Instance.playerUi.UpdateEnemyInformationPanel(this); if (CurHp <= 0) { Die(); } }
public override void TakeDamage(int damageAmount) { _audioPlayer.PlayAudioSource(); _enemyAnimatorHandler.PlayDamagedAnimation(); OnEnemyHit?.Invoke(); base.TakeDamage(damageAmount); }
public bool HitByEnemy(EnemyType enemyType) { if (movementType == MovementType.Run) { OnEnemyHit?.Invoke(); return(true); } return(false); }
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); }
void Shoot() { RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); OnEnemyHit enemy = hit.transform.GetComponent <OnEnemyHit>(); if (enemy != null) { enemy.TakeDamage(damage); } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Enemy")) { Enemy enemy = other.GetComponent <Enemy>(); if (enemy.EnemyHealth.CurrentHealth > 0f) { OnEnemyHit?.Invoke(enemy, damage); enemy.EnemyHealth.DealDamage(damage); } ObjectPooler.ReturnToPool(gameObject); } }
// Start is called before the first frame update void Start() { rb = GetComponent <Rigidbody2D>(); col = GetComponent <Collider2D>(); animator = this.GetComponentInChildren <Animator>(); runningSpeed = speed + 4f; selfCollider = GetComponent <Collider2D>(); applyLayerMaskToChildren(); // Set up hit delegate OnEnemyHit oehScript = GetComponent <OnEnemyHit>(); oehScript.executionDelegate = OnEnemyHitEffect; // Definitions defScript = GetComponent <CharacterDefinitions>(); stats = defScript.stats; heroCharacterScript = GetComponent <Character>(); gameController = GameObject.FindGameObjectWithTag("GameController"); }
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(); } }
public void Hit(float damage) { OnEnemyHit.Invoke(damage); }
public static void ReportEnemyHit() { OnEnemyHit?.Invoke(); //Debug.Log("Enemy Hit Event"); }
public void OnEnemy() { OnEnemyHit?.Invoke(); }