private void OnTriggerEnter2D(Collider2D collision) { //Debug.Log(collision.name); if (collision.gameObject.tag == "Arrow") { //ContactFilter2D filter = new ContactFilter2D(); //Collider2D[] cols = new Collider2D[2]; //collision.OverlapCollider(filter, cols); //foreach (Collider2D d in cols) //{ // Debug.Log(d.name); //} Damageable.CollisionInfo i = new Damageable.CollisionInfo(); i.position = collision.transform.position; i.totalDmg = 1; dmg.DealDamage(i); Debug.Log("OUCH"); Destroy(collision.gameObject); } }
// Update is called once per frame void Update() { //RaycastHit hit; Collider[] hit = Physics.OverlapSphere(transform.position, 0.5f, mask); foreach (Collider c in hit) { Damageable d = null; if (d = c.GetComponent <Damageable>()) { if (d.transform == owner) { Debug.Log("SELF"); return; } if (!d.isHitStun) { OnHit.Invoke(); } d.DealDamage(1); //Debug.Log("HURT " + d.name); } } }
IEnumerator Burn() { yield return(new WaitForSeconds(3)); dmg.DealDamage(1); anim.Play("Default"); }
public override void OnCollisionEvent(Collision collision) { // Ignore Triggers if (collision.collider.isTrigger) { return; } Rigidbody rb = GetComponent <Rigidbody>(); if (rb && MinForceHit != 0) { float zVel = System.Math.Abs(transform.InverseTransformDirection(rb.velocity).z); // Minimum Force not achieved if (zVel < MinForceHit) { return; } } hitPosition = collision.contacts[0].point; Vector3 normal = collision.contacts[0].normal; Quaternion hitNormal = Quaternion.FromToRotation(Vector3.forward, normal); // FX - Particles, Decals, etc. DoHitFX(hitPosition, hitNormal, collision.collider); var col = Physics.OverlapSphere(hitPosition, explosionRadius); foreach (var c in col) { // Damage if possible Damageable d = c.GetComponent <Damageable>(); if (d) { d.DealDamage(Damage); if (onDealtDamageEvent != null) { onDealtDamageEvent.Invoke(); } } c.SendMessageUpwards("HitCallback", new HealthManager.DamageInfo(c.transform.position, (c.transform.position - hitPosition).normalized, 200f, c), SendMessageOptions.DontRequireReceiver); } if (StickToObject) { // tryStickToObject } else { // Done with this projectile Destroy(this.gameObject); } }
// Update is called once per frame void FixedUpdate() { if (willDealDamage && currentTarget != null) { //If dealing damage completes level if (currentTarget.DealDamage(damageToDealPerUpdate)) { LevelSpawner.SpawnNewLevel(); } } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.layer == LayerMask.NameToLayer("Water")) { splash.transform.position = transform.position; if (splash) { splash.Play(); } Debug.Log("DROWN"); dmg.DealDamage(1); sfx.PlayOneShot(splashSFX); } }
private void OnTriggerStay2D(Collider2D collision) { if (collision.gameObject.layer == LayerMask.NameToLayer("Enemy")) { Damageable.CollisionInfo info = new Damageable.CollisionInfo(); info.totalDmg = 1; info.knockbackForce = 10; info.position = collision.transform.root.position; //info.position=transform.position- damageable.DealDamage(info); //damageable.DealDamage(1); Debug.Log("ENEMY HURTS ME"); } }
protected override void ProcessInputs(out bool processAllOutputs) { GameObject target = (GameObject) inputs[0].GetData(); float power = (float)inputs[1].GetData(); Damageable damageable = target.GetComponent<Damageable>(); if(damageable != null) { damageable.DealDamage((int)power); } else { Debug.Log("this target is not damageable (" + target + ")"); } //TODO take in account player's level processAllOutputs = false; }
private void OnTriggerStay2D(Collider2D collision) { if (collision.gameObject.layer == LayerMask.NameToLayer("Enemy")) { collision.GetComponent <Damageable>().DealDamage(0, 10, transform.position); pD.DealDamage(0, 5, collision.transform.position); StartCoroutine(Flash()); //////Damageable.CollisionInfo info = new Damageable.CollisionInfo(); //info.totalDmg = 1; //info.knockbackForce = 10; //info.position = collision.transform.root.position; ////info.position=transform.position- //damageable.DealDamage(info); //damageable.DealDamage(1); //Debug.Log("ENEMY HURTS ME"); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Area") { Debug.Log("CHANGE AREA"); //if(lastArea!=null) //{ // lastArea.DisableEnemies(); //} currentArea = collision.GetComponent <Area>(); //currentArea.EnableEnemies(); //lastArea = currentArea; if (!changearea) { StartCoroutine(ChangeArea(collision.transform.position)); } } if (collision.tag == "Teleport") { Debug.Log("TELE INDORS"); tele = collision.gameObject.GetComponent <Teleporter>(); StartCoroutine(TeleportPlayer()); } //if (damageable) //{ // if (collision.tag == "Enemy") // { // Damageable.CollisionInfo i = new Damageable.CollisionInfo(); // i.position = collision.transform.position; // i.totalDmg = 1; // damageable.DealDamage(i); // //PlayHitStun(); // Debug.Log("OUCH"); // } // if (collision.tag == "Health1") // { // damageable.HealAdditive(3); // Destroy(collision.gameObject); // } //} //if (collision.tag == "Fire") //{ // Debug.Log("BURN"); // Status.StartBurning(); //} //-------------------------------- if (collision.tag == "Gold") { Debug.Log("COIN"); if (OnCollectCoin != null) { OnCollectCoin(100); } Destroy(collision.gameObject); //Debug.Log("BURN"); //Status.StartBurning(); } //if (collision.tag == "HealthUp") //{ // damageable.UpgradeHealth(2); // sfx.PlayOneShot(healthSFX); // Destroy(collision.gameObject); //} if (collision.tag == "Heal") { damageable.HealAdditive(12); sfx.PlayOneShot(healthSFX); Destroy(collision.gameObject); } if (collision.tag == "ArrowCollect") { //damageable.HealAdditive(1); bow.AddAmmo(3); sfx.PlayOneShot(healthSFX); Destroy(collision.gameObject); } if (collision.tag == "BombCollect") { //damageable.HealAdditive(1); bomb.AddAmmo(3); sfx.PlayOneShot(healthSFX); Destroy(collision.gameObject); } //------------------------------------- //if(collision.gameObject.layer==LayerMask.NameToLayer("Collectable")) //{ // Debug.Log("Collect"); // collision.GetComponent<Collectable>().OnCollect.Invoke(); //} if (collision.tag == "Projectile") { collision.GetComponent <Projectile>().CleanUp.Invoke(); Damageable.CollisionInfo i = new Damageable.CollisionInfo(); i.position = -collision.transform.position; i.totalDmg = 1; bow.Dispose(); damageable.DealDamage(i); } //collision. //Debug.Log(collision.name); }