private void HandleDamageCheck() { ContactFilter2D lFilter = new ContactFilter2D(); lFilter.useLayerMask = true; lFilter.useTriggers = false; lFilter.layerMask = Damagables; Collider2D[] contactResults = new Collider2D[10]; int lNumCol = Physics2D.OverlapBox(rb.position, new Vector2(1f, 0.5f), 0f, lFilter, contactResults); if (lNumCol > 0) { foreach (Collider2D lColl in contactResults) { if (lColl != null && lColl.gameObject != gameObject && lColl.gameObject != spawnParent) { Damagable dmg = lColl.GetComponent <Damagable>(); if (dmg != null) { dmg.Damage(1); Instantiate(hitPrefab, rb.position, Quaternion.identity); GameManager.instance.RemoveMetalFrag(this); Destroy(gameObject); break; } } } } contactResults = new Collider2D[10]; }
public bool Damage(float dmg, float headMult) // Returns true if you killed them { float overallDmg = dmg; overallDmg *= (damageZone == Zone.head) ? headMult : 1f; return(damagable.Damage(overallDmg)); }
void OnTriggerStay(Collider other) { Damagable d = other.gameObject.GetComponent <Damagable>(); if (d != null && d.team != team && timerAttack == 0) { d.Damage(); Debug.Log(d.gameObject.name + " health: " + d.health); timerAttack = attackDelay; } }
void OnTriggerStay(Collider other) { if (other.transform != user.transform) { Damagable hitTarget = other.transform.GetComponent <Damagable>(); if (IsPlay && hitTarget != null && user.CanDamageTarget(hitTarget)) { hitTarget.Damage(DirectDamageType, this, user); } //Destroy(gameObject); } }
public virtual void OnTriggerEnter(Collider other) { //Debug.Log("OnTriggerEnter" + other.gameObject.name); if (other.transform != user.transform) { Damagable hitTarget = other.transform.GetComponent <Damagable>(); if (IsPlay && hitTarget != null && user.CanDamageTarget(hitTarget)) { hitTarget.Damage(DirectDamageType, new DirectDamageMaker(user, DirectDamageType, skillSetting.AdjustedDamage), user); } //Destroy(gameObject); } }
public IEnumerator Explode() { exploding = true; rb.velocity = Vector2.zero; mag.SetClickBuffer(false); yield return(new WaitForSeconds(0.01f * anim.speed)); CameraControl.instance.Shake(0.15f, 8, 7f); ContactFilter2D filter = new ContactFilter2D(); filter.layerMask = Damagables; Collider2D[] collResults = new Collider2D[20]; Physics2D.OverlapCircle(transform.position, explosionRadius, filter, collResults); foreach (Collider2D coll in collResults) { if (coll != null) { Damagable dmg = coll.gameObject.GetComponent <Damagable>(); if (coll != collider && dmg != null) { if (coll.GetComponent <PlayerBehaviour>() != null) { Vector2 lBounceDir = (coll.transform.position - transform.position).normalized; if (!PlayerBehaviour.instance.Invulnerable) { PlayerBehaviour.instance.StartBounceBack(lBounceDir * 2f); } } dmg.Damage(explosionDamage); } } } int lCount = 0; while (lCount < 2) { MetalFrag frag = GameManager.instance.SpawnMetalFrag(rb.position, Quaternion.identity); frag.spawnParent = gameObject; int randF_X = Random.Range(-10, 10); int randF_Y = Random.Range(-10, 10); frag.GetComponent <Rigidbody2D>().velocity = new Vector2(randF_X / 2f, randF_Y / 2f); lCount++; } yield return(new WaitForSeconds(1.123f * anim.speed)); Die(); }
void OnTriggerEnter(Collider other) { //Debug.Log("OnTriggerEnter" + other.gameObject.name); if (other.transform != firer) { Damagable hitTarget = other.transform.GetComponent <Damagable>(); if (hitTarget != null && !hit && firerChar.CanDamageTarget(hitTarget)) { hit = true; hitTarget.Damage(damageType, firerChar, firerChar); transform.parent = other.transform; } //Destroy(gameObject); } }
public void HitEvent(float radius = 0.3f, float damageActionScale = 1.0f, Vector3 sphereOffset = default(Vector3), bool relativeHit = false) { //GameObject checkSphere = GameObject.Find("Body/rightHand"); Collider[] hitObj = Physics.OverlapSphere(checkSphere.transform.position + sphereOffset, radius); Debug.Log("qqqq1"); foreach (Collider c in hitObj) { Debug.Log("qqqq2"); Debug.Log(c.gameObject.tag); Damagable cDamamgable = c.gameObject.GetComponent <Damagable>(); if (c.gameObject != gameObject && cDamamgable != null) { Debug.Log("qqqq3"); if (relativeHit) { cDamamgable.Damage((c.transform.position - gameObject.transform.position).normalized * damageActionScale, ATK); } else { cDamamgable.Damage(gameObject.transform.forward * damageActionScale, ATK); } } } }
private void MeleeWeapon_hitOnCharacter(Damagable character) { if (!targetsHit.Contains(character)) { targetsHit.Add(character); } else { if (!IsMultiAttack) { return; } } AddEffectOnWeaponHit(character); character.Damage(EffectDamageType, this, user); }
private void OnTriggerEnter(Collider other) { Instantiate(impactEffectPrefab, tf.position, Quaternion.Euler(tf.rotation.eulerAngles)); gameObject.SetActive(false); //If the gameObject the projectile hits can take damage Damagable damagable = other.gameObject.GetComponentInParent <Damagable>() == null?other.gameObject.GetComponent <Damagable>() : other.gameObject.GetComponentInParent <Damagable>(); //If the gameObject dies add to the players score if (damagable != null) { //Debug.Log("Damage: " + damagable.Damage(damage)); int[] stats = damagable.Damage(damage); owner.stats.kills += stats[0]; owner.stats.score += stats[1]; } }
void OnCollisionEnter(Collision collision) { if (Damage == 0) { return; } Damagable damagable = collision.gameObject.GetComponent <Damagable>(); if (damagable == null) { return; } damagable.Damage(Damage); Destroy(gameObject); }
private void Melee(Transform origin, Transform target) { RaycastHit[] hits = Physics.RaycastAll(origin.position, (target.position - origin.position).normalized * MaxRange); Damagable damagable = hits.Select(hit => hit.collider.gameObject.GetComponent <Damagable>()) .First(component => component != null); damagable.Damage(Damage); Rigidbody body = hits.Select(hit => hit.rigidbody).First(rb => rb != null); if (body == null) { return; } body.AddForce((target.position - origin.position).normalized * KnockBack, ForceMode.Impulse); }
//check if character grounded, update mGrounded void GroundStateCheck() { /* * RaycastHit hit; * if (Physics.Raycast(mGroundCheck.position + Vector3.up * 0.1f, Vector3.down, out hit, groundCheckDistance)) * mGrounded = true; * else * mGrounded = false; */ //leaving ground if (mGrounded == true && mGroundTrigger.isGrounded() == false) { if (mDamaged == false) { jumpVelocity = new Vector3(mRigidbody.velocity.x, 0, mRigidbody.velocity.z); } } //entering ground else if (mGrounded == false && mGroundTrigger.isGrounded() == true) { if (mDamaged == true) { mDamaged = false; } //falling damage maangement if (!mJumpAttack && !mRoll && fallingSpeed > 9.0f) { mDamagable.Damage(Vector3.zero, fallingSpeed * 2.0f); } fallingSpeed = 0.0f; fallingSpeedRecording = true; } float VY = -mRigidbody.velocity.y; if ((mGroundTrigger.isGrounded()) || (VY < 0.1f && VY > 0.0f)) { if (mJumpAttack) { JumpAttackCompleteEvent(); } } mGrounded = mGroundTrigger.isGrounded(); }
void OnTriggerEnter(Collider other) { Damagable targetDamage = other.GetComponent <Damagable>(); if (_user && targetDamage != null && other.gameObject != _user && !other.CompareTag(Tags.DeadBody)) { if (userChar.CanDamageTarget(targetDamage)) { //處發擊中事件 if (hitOnCharacter != null) { hitOnCharacter(targetDamage); } //攻擊或發動技能時可造成傷害 if ((userChar.IsAttacking || userChar.IsSkilling)) { //攻擊(不是放技能) if (!userChar.IsSkilling) { //不在這次打擊過的清單 if (!hitOnOneAttack.Contains(targetDamage)) { //加入 hitOnOneAttack.Add(targetDamage); //攻擊成功 一次傷害判定,若為技能不影響取得傷害的部分 targetDamage.Damage(DamageType.Physical, userChar, userChar); } //已打擊過 else { //啥都不做 return; } } else { //技能觸發OnHitCharacter造成傷害 } } } } }
protected IEnumerator AttackRoutine() { if (target == null || Vector3.Distance(transform.position, target.transform.position) > range) { target = null; yield return(null); } else { laserRenderer.SetPosition(0, transform.position); laserRenderer.SetPosition(1, target.transform.position); laserRenderer.enabled = true; StartCoroutine("HideLaser"); target.Damage(damage); yield return(new WaitForSeconds(attackInterval)); StartCoroutine("AttackRoutine"); } }
public void DamageNetwork(float value) { damagable.Damage(value); }
static float DefaultOnHit(Damagable target) { target.Damage(100f); return(100f); }
public override void OnWeaponHit(Damagable damageManager) { print("Triggered"); damageManager.Damage(Damage); this.animator.SetTrigger("Stop"); }