private void OnTriggerEnter2D(Collider2D collision) { if (collision.TryGetComponent(out Attacker attacker)) { Destroy(attacker.gameObject, 3); healthDisplay.TakeDamage(1); } }
public float DamageObj(float damage) { if (!Alive) { return(0f); } float healthBefore = m_health; m_health = Mathf.Max(Mathf.Min(MaxHealth, m_health - damage), 0); Alive = (m_health > 0); float diff = m_health - healthBefore; if (m_display != null) { m_display.TakeDamage(diff, m_health); } return(diff); }
public void MoveTowardsNextNode() { Vector3 delta = nextNode.transform.position - transform.position; phys.velocity = delta.normalized * moveSpeed; Debug.Log(delta); if (delta.magnitude < closeEnough) { Debug.Log("CLOSE ENUF"); nodeIndex++; if (nodeIndex >= nodes.Count) { healthDisplay.TakeDamage(1); Destroy(this.gameObject); } else { nextNode = nodes [nodeIndex]; } } }
private void ProcessHit(DamageDealer damageDealer) { if (damageDealer.CompareTag("PlayerShot")) { return; } damageSound.Play(); //meshRenderer.material = flashMaterial; health -= damageDealer.GetDamage(); healthDisplay.TakeDamage(1); // Subtracts one heart from the heartdisplay script agent.AddReward(-0.2f); damageDealer.Hit(); if (health <= 0) { Die(); } else { //Invoke("ResetMaterial", .1f); } }