public virtual void OnTriggerEnter(Collider collider) { ProjectilePlayer projectile = collider.gameObject.GetComponent <ProjectilePlayer>(); if (projectile != null) { projectile.Die(); healthController.Damage(projectile.damage); HitFromDirection = projectile.Velocity.normalized; if (onHit != null) { onHit.Invoke(this); } } PlayerController player = collider.gameObject.GetComponent <PlayerController>(); if (player != null) { player.healthController.Damage(damagePlayerWhenCollide); healthController.Damage(damagePlayerWhenCollide); } }
void Start() { animator = GetComponent <Animator>(); _meleeHitBox.SetActive(false); _meleeHitBoxCrouch.SetActive(false); _projectilePlayer = GameManager.instance.player.GetComponent <ProjectilePlayer>(); }
void OnCollisionEnter(Collision coll) { /*GameObject otherGO = coll.gameObject; // a * if (otherGO.tag == "ProjectilePlayer") * { // b * Destroy(otherGO); // Destroy the Projectile * Destroy(gameObject); // Destroy this Enemy GameObject * } * else * { * print("Enemy hit by non-ProjectilePlayer: " + otherGO.name); // c * }*/ GameObject otherGo = coll.gameObject; switch (otherGo.tag) { case "ProjectilePlayer": // b ProjectilePlayer p = otherGo.GetComponent <ProjectilePlayer>(); // If this Enemy is off screen, don't damage it. if (!bndCheck.isOnScreen) { // c Destroy(otherGo); break; } ShowDamage(); // d health -= Main.GetWeaponDefinition(p.type).damageOnHit; if (health <= 0) { // d // Destroy this Enemy if (!notifiedOfDestruction) { Main.S.shipDestroyed(this); } // Destroy(this.gameObject); notifiedOfDestruction = true; // Destroy this Enemy Destroy(this.gameObject); } Destroy(otherGo); // e break; default: print("Enemy hit by non-ProjectilePlayer: " + otherGo.name); // f break; } // Hurt this Enemy // Get the damage amount from the Main WEAP_DICT. }
private void OnTriggerEnter(Collider collision) { //if (collision.gameObject.tag == "Laser") na tagach ProjectilePlayer missle = collision.gameObject.GetComponent <ProjectilePlayer>(); if (missle) { health -= missle.GetDmg(); missle.Hit(); if (health <= 0) { Destroy(gameObject); scoreKeeper.ScorePoints(enemyscore); AudioSource.PlayClipAtPoint(enemydestroyed, transform.position); } } //Debug.Log("enemy hit"); //Destroy(collision.gameObject); }
public void OnTriggerEnter(Collider col) { ProjectilePlayer missle = col.gameObject.GetComponent <ProjectilePlayer>(); if (missle) { missle.Hit(); Debug.Log("statek/pocisk"); Instantiate(Explosion, transform.position, Quaternion.identity); Destroy(gameObject); scorekeeper.ScorePoints(scorevalue); } PlayerController player = col.gameObject.GetComponent <PlayerController>(); if (player) { Debug.Log("statek/player"); Instantiate(Explosion, transform.position, Quaternion.identity); Destroy(gameObject); } }
public ProjectilePlayer MakeProjectile() { // m GameObject go = Instantiate <GameObject>(def.projectilePrefab); if (transform.parent.gameObject.tag == "Player") { // n go.tag = "ProjectilePlayer"; go.layer = LayerMask.NameToLayer("ProjectilePlayer"); } else { go.tag = "ProjectileEnemy"; go.layer = LayerMask.NameToLayer("ProjectileEnemy"); } go.transform.position = collar.transform.position; go.transform.SetParent(PROJECTILE_ANCHOR, true); // o ProjectilePlayer p = go.GetComponent <ProjectilePlayer>(); p.type = type; lastShotTime = Time.time; // p return(p); }
// This will override the OnCollisionEnter that is part of Enemy.cs. void OnCollisionEnter(Collision coll) { // e GameObject other = coll.gameObject; switch (other.tag) { case "ProjectilePlayer": ProjectilePlayer p = other.GetComponent <ProjectilePlayer>(); // If this Enemy is off screen, don't damage it. if (!bndCheck.isOnScreen) { Destroy(other); break; } // Hurt this Enemy GameObject goHit = coll.contacts[0].thisCollider.gameObject; // f Part prtHit = FindPart(goHit); if (prtHit == null) { // If prtHit wasn't found… // g goHit = coll.contacts[0].otherCollider.gameObject; prtHit = FindPart(goHit); } // Check whether this part is still protected if (prtHit.protectedBy != null) { // h foreach (string s in prtHit.protectedBy) { // If one of the protecting parts hasn't been destroyed... if (!Destroyed(s)) { // ...then don't damage this part yet Destroy(other); // Destroy the ProjectilePlayer return; // return before damaging Enemy_4 } } } // It's not protected, so make it take damage // Get the damage amount from the Projectile.type and Main.W_DEFS$$$$$$$$$$$$$$$$ prtHit.health -= Main.GetWeaponDefinition(p.type).damageOnHit; // Show damage on the part ShowLocalizedDamage(prtHit.mat); if (prtHit.health <= 0) { // i // Instead of destroying this enemy, disable the damaged part prtHit.go.SetActive(false); } // Check to see if the whole ship is destroyed bool allDestroyed = true; // Assume it is destroyed foreach (Part prt in parts) { if (!Destroyed(prt)) { // If a part still exists... allDestroyed = false; // ...change allDestroyed to false break; // & break out of the foreach loop } } if (allDestroyed) { // If it IS completely destroyed... // j // ...tell the Main singleton that this ship was destroyed Main.S.shipDestroyed(this); // Destroy this Enemy Destroy(this.gameObject); } Destroy(other); // Destroy the ProjectilePlayer break; } }