void OnTriggerEnter(Collider col) { isCausingDamage = true; if (col.transform.tag == "Player") { customCharController player = col.transform.GetComponent <customCharController>(); if (player != null && player.isDead != true) { if (repeating) { StartCoroutine(TakeDamage(player, damageRepeatRate)); } else { player.TakeDamge(damage); } } } if (col.transform.tag == "tent") { Debug.Log("I have collided with the tent"); BaseScript baseScript = col.transform.GetComponentInParent <BaseScript>(); if (baseScript != null && baseScript.isDestroyed != true) { agent.SetDestination(transform.position); anim.SetBool("run", false); if (repeating) { StartCoroutine(TakeDamage(baseScript, damageRepeatRate)); } else { baseScript.TakeDamage(damage); } } } }
public virtual void TakeDamage(DamageInfo info) { if (!isDead) { health -= info.damage; //hitStun = info.hitStun; velocity.x = info.knockback.x; velocity.y = info.knockback.y; isHurt = true; if (0 >= health) { isDead = true; animator.SetBool("isDead", isDead); //health = 0; //GameObject.Find(Tags.MAIN_CAMERA).GetComponent<CameraScript>().SetFocus(null); if (null != inBase) { inBase.TakeDamage(tag); } if (null != mission) { mission.TargetDefeated(); } //if (!isDead) LevelScript.enemiesKOd++; if (0 == velocity.x) { velocity.x = 2f * -transform.localScale.x; } if (0 == velocity.y) { if (!inAir) { //startPosition.y = transform.position.y + cInfo.footOffset; startPosition.y = transform.position.z; } velocity.y = 5f; // Generic Death Knockback need to send it which direction it came in inAir = true; horizDampEnable = false; animator.SetTrigger("AirHurt"); } } if (velocity.y > 0) { if (!inAir) { startPosition.y = transform.position.z; } inAir = true; horizDampEnable = false; animator.SetTrigger("AirHurt"); } else { animator.SetTrigger("Hurt"); } animator.SetBool("inAir", inAir); } }