public void HandleDamage(Collider co) { if (!IsDead()) { if (Time.time > damageTimeStamp) { ProjectileScript projGo = co.GetComponentInParent <ProjectileScript>(); SetHealth(GetHealth() - projGo.GetDamage()); damageTimeStamp = Time.time + damageIFrameRate; if (GetComponent <AudioSource>().clip != hurt) { GetComponent <AudioSource>().clip = hurt; } GetComponent <AudioSource>().PlayOneShot(hurt); //blood spatter Vector3 position = new Vector3(transform.position.x, transform.position.y + gameObject.GetComponent <BoxCollider>().bounds.extents.y *1.5f); GameObject blood = Instantiate(hurtEffect, position, Quaternion.identity, GameObject.Find("Environment").transform); blood.name = hurtEffect.name; if (co && co.GetComponentInParent <ProjectileScript>().GetParent().transform.position.x > transform.position.x) { blood.GetComponent <SpriteRenderer>().flipX = true; } if (co && co.transform.parent.gameObject.name == "blankmelee" || co && co.transform.parent.gameObject.name == "Playerblankmelee") { blood.GetComponent <SpriteRenderer>().flipX = !blood.GetComponent <SpriteRenderer>().flipX; } Destroy(blood, hurtAnimDuration); StartCoroutine(LeaveBloodstain(co, blood.GetComponent <SpriteRenderer>().flipX)); HandleDeath(); } } }
void OnTriggerEnter2D(Collider2D trigger) { //Debug.Log("Player Hit"); ProjectileScript missile = trigger.gameObject.GetComponent <ProjectileScript>(); if (missile) { health -= missile.GetDamage(); missile.Hit(); if (health <= 0) { Die(); } } }
void OnTriggerEnter2D(Collider2D trigger) { //Debug.Log ("Enemy Hit"); ProjectileScript missile = trigger.gameObject.GetComponent <ProjectileScript>(); if (missile) { health -= missile.GetDamage(); missile.Hit(); if (health <= 0) { AudioSource.PlayClipAtPoint(enemyDies, transform.position, 0.5f); Destroy(gameObject); scoreKeeper.Score(scoreValue); } } }
void OnTriggerEnter2D(Collider2D coll) { string tag = coll.gameObject.tag; ProjectileScript obj = coll.gameObject.GetComponent <ProjectileScript>(); Debug.Log(health); if (tag == "enemylaser") { health -= obj.GetDamage(); obj.Hit(); AudioSource.PlayClipAtPoint(hitAudio, transform.position); if (health <= 0) { Die(); } } }
private void HitByProjectile(ProjectileScript projectile) { var velocity = projectile.GetComponent <Rigidbody2D>().velocity; if (velocity.y > 0) { return; } var damage = projectile.GetDamage(); Hp = Hp - damage; Debug.Log(Hp); if (Hp <= 0) { Die(); } }
void OnTriggerEnter2D(Collider2D coll) { string tag = coll.gameObject.tag; ProjectileScript obj = coll.gameObject.GetComponent <ProjectileScript>(); if (tag == "laser") { health -= obj.GetDamage(); obj.Hit(); AudioSource.PlayClipAtPoint(hitAudio, transform.position); if (health <= 0) { AudioSource.PlayClipAtPoint(destroyAudio, transform.position); score.Score(scoreValue); Destroy(gameObject); } } }
void OnTriggerEnter2D(Collider2D collider) { ProjectileScript projectile = collider.gameObject.GetComponent <ProjectileScript>(); if (projectile) { health -= projectile.GetDamage(); projectile.Hit(); if (health <= 0) { var enemyGameObject = gameObject.GetComponent <EnemyBehaviour>(); if (enemyGameObject) { enemyGameObject.Die(); } else { Debug.Log("GameObject has Health Script, but is not an enemy."); } } } }