void OnTriggerEnter(Collider c) { GameObject other = c.gameObject; if (other.tag == "Enemy") { string damageType = "none"; float force = 5; if (augment != null) { augment.onHitEffect(other); damageType = augment.Element; if (augment.Element == "earth") { force = 20; } } //TODO: Add enemy Knockback Vector3 enemyPos = other.transform.position; Vector3 playerPos = transform.parent.position; other.GetComponent <Rigidbody>().AddForce((enemyPos - playerPos) * force, ForceMode.VelocityChange); EnemyStats enemyHP = other.GetComponent <EnemyStats> (); if (isSwinging) { enemyHP.TakeDamage(swordDamage, damageType); } } }
void OnTriggerEnter(Collider c) { GameObject other = c.gameObject; //If it hits a player don't disappear if (other.tag != "Player" && other.tag != "Bullet" && other.tag != "Room" && other.tag != "TutorialRoom" && other.tag != "Pickups" && other.tag != "Pipe") { AP.PlayClip("SFX/bullet_die", 0.05f); Destroy(gameObject); } if (other.tag == "Bullet" || other.tag == "Pickups") { Physics.IgnoreCollision(other.GetComponent <Collider> (), GetComponent <Collider> ()); } if (other.tag == "Enemy") { string damageType = "none"; float force = 50; if (augment != null) { Debug.Log(""); //Destroy (collision.gameObject); augment.onHitEffect(other); damageType = augment.Element; if (augment.Element == "earth") { force = 1000; } } Vector3 bulletDir = this.gameObject.transform.forward; bulletDir.y = 0; other.GetComponent <Rigidbody> ().AddForce(bulletDir.normalized * force); EnemyStats enemyHP = other.GetComponent <EnemyStats>(); enemyHP.TakeDamage(bulletDamage, damageType); } }
void OnTriggerEnter(Collider c) { GameObject other = c.gameObject; //If it hits a player don't disappear if (other.tag != "Enemy" && other.tag != "Bullet" && other.tag != "Room" && other.tag != "Pipe") { Destroy(gameObject); } if (other.tag == "Bullet") { Physics.IgnoreCollision(other.GetComponent <Collider> (), GetComponent <Collider> ()); } if (other.tag == "Player") { string damageType = "none"; bool playersTogether = GameObject.FindWithTag("Canvas").GetComponent <GameStats>().PlayersTogether; if (!playersTogether) { GameObject.Find("Camera" + other.name).GetComponent <CameraShaker> ().shake = 0.1f; } else { GameObject.Find("CameraP1").GetComponent <CameraShaker> ().shake = 0.1f; } if (augment != null) { Debug.Log(""); //Destroy (collision.gameObject); augment.onHitEffect(other); damageType = augment.Element; } HealthManager.DamageHealth(bulletDamage); } }
IEnumerator FireLaser() { line.enabled = true; aug = GetComponent<StatsManager> ().GetAugment (); if (aug != null) { if (aug.Element == "fire") { rayGunTip.GetComponent<Renderer> ().material = Resources.Load<Material> ("LaserRed"); } else if (aug.Element == "ice") { rayGunTip.GetComponent<Renderer> ().material = Resources.Load<Material> ("LaserBlue"); } else if (aug.Element == "earth") { rayGunTip.GetComponent<Renderer> ().material = Resources.Load<Material> ("LaserGreen"); } } else { rayGunTip.GetComponent<Renderer> ().material = Resources.Load<Material> ("LaserDefault"); } while (playerShooting) { audioPlacement.PlayClip("beep/beep_2", 0.04f); Ray ray = new Ray (rayGunTip.transform.position, transform.forward * -1); RaycastHit hit; line.SetPosition (0, ray.origin); if (Physics.Raycast(ray, out hit, 50)) { line.SetPosition(1, hit.point); if (hit.transform.tag == "Enemy") { string damageType = "none"; float force = 0; if (aug != null) { aug.onHitEffect (hit.transform.gameObject); damageType = aug.Element; if (aug.Element == "earth") { force = 70; } } //Add force to enemy hit.rigidbody.AddForceAtPosition(transform.forward * force * -1, hit.point); EnemyStats enemyHP = hit.transform.GetComponent<EnemyStats> (); enemyHP.TakeDamage (0.18f, damageType); } } else { line.SetPosition (1, ray.GetPoint (50)); } yield return null; } line.enabled = false; }
IEnumerator FireLaser() { line.enabled = true; aug = GetComponent <StatsManager> ().GetAugment(); if (aug != null) { if (aug.Element == "fire") { rayGunTip.GetComponent <Renderer> ().material = Resources.Load <Material> ("LaserRed"); } else if (aug.Element == "ice") { rayGunTip.GetComponent <Renderer> ().material = Resources.Load <Material> ("LaserBlue"); } else if (aug.Element == "earth") { rayGunTip.GetComponent <Renderer> ().material = Resources.Load <Material> ("LaserGreen"); } } else { rayGunTip.GetComponent <Renderer> ().material = Resources.Load <Material> ("LaserDefault"); } while (playerShooting) { audioPlacement.PlayClip("beep/beep_2", 0.04f); Ray ray = new Ray(rayGunTip.transform.position, transform.forward * -1); RaycastHit hit; line.SetPosition(0, ray.origin); if (Physics.Raycast(ray, out hit, 50)) { line.SetPosition(1, hit.point); if (hit.transform.tag == "Enemy") { string damageType = "none"; float force = 0; if (aug != null) { aug.onHitEffect(hit.transform.gameObject); damageType = aug.Element; if (aug.Element == "earth") { force = 70; } } //Add force to enemy hit.rigidbody.AddForceAtPosition(transform.forward * force * -1, hit.point); EnemyStats enemyHP = hit.transform.GetComponent <EnemyStats> (); enemyHP.TakeDamage(0.18f, damageType); } } else { line.SetPosition(1, ray.GetPoint(50)); } yield return(null); } line.enabled = false; }