private void OnTriggerEnter(Collider other) { if (other.gameObject.name == "Pet(Clone)") { CanDamage = false; } if (CanDamage) { if (CanSwing) { IDamage damageInterface = other.GetComponent <IDamage>(); if (damageInterface != null) { damageInterface.TakeDamage(Damage); damageInterface.SetDamageText(Damage, Crit); //playerref.StopAnim(); //playerref.CanMove(); //playerref.AnimationEvent(); //PC.canMove = true; //SwordRef.anim.SetBool("Swing", false); //PR.CanTurn = true; // SwordRef.canSwing = true; CanSwing = false; } } } else { CanDamage = true; // INCASE THE PLAYER HITS THE PET } }
void AirbotHit() { hitCount = Physics2D.BoxCastNonAlloc(transform.position, box.size, 0, velocity, RaycastHits, raylength, Global.CharacterDamageLayers); for (int i = 0; i < hitCount; i++) { hit = RaycastHits[i]; IDamage dam = hit.transform.GetComponent <IDamage>(); if (dam != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = this; dmg.damageSource = transform; dmg.point = hit.point; if (dam.TakeDamage(dmg)) { hitpause = true; pathAgent.SetPath(new Vector3(hit.point.x, hit.point.y, 0) + Vector3.up * hitPauseOffset); animator.Play("laugh"); hitPauseTimer.Start(1, null, delegate { hitpause = false; animator.Play("idle"); }); } } } }
void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { Transform objectHit = hit.transform; MonoBehaviour[] mono; mono = objectHit.gameObject.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour item in mono) { if (item is IDamage) { IDamage temp = item as IDamage; temp.TakeDamage(); return; } } } } }
void Boom() { if (flagBoom) { return; } flagBoom = true; // disable collider before explosion to avoid unnecessary OnCollisionEnter2D() calls circle.enabled = false; timeoutTimer.Stop(false); int count = Physics2D.OverlapCircleNonAlloc(transform.position, BoomRadius, clds, Global.DamageCollideLayers); for (int i = 0; i < count; i++) { if (clds[i] != null) { IDamage dam = clds[i].GetComponent <IDamage>(); if (dam != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = instigator; dmg.damageSource = transform; dmg.point = transform.position; dam.TakeDamage(dmg); } } } Destroy(gameObject); Instantiate(explosion, transform.position, Quaternion.identity); }
void Update() { if (Input.GetKeyDown(KeyCode.P)) { Destroy(gameObject); } if (Input.GetKeyDown(KeyCode.S)) { agent.ResetPath(); } if (Input.GetMouseButtonDown(0)) { if (!EventSystem.current.IsPointerOverGameObject()) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider.tag == "Ground") { curTarget = null; agent.SetDestination(hit.point); } else if (hit.collider.tag == "Enemy") { curTarget = hit.transform; } } } } if (curTarget) { rangeToTarget = (curTarget.transform.position - transform.position).sqrMagnitude; if (rangeToTarget > atkRangeSqr) { agent.SetDestination(curTarget.position); } else { agent.ResetPath(); anim.SetTrigger("Attack"); IDamage unit = curTarget.GetComponent <IDamage>(); unit.TakeDamage(0); } } if (!agent.hasPath) { anim.SetBool("Run", false); } else { anim.SetBool("Run", true); } }
void OnTriggerEnter2D(Collider2D col) { if (col.tag.Equals("Enemy")) { IDamage d = (IDamage)col.gameObject.GetComponent(typeof(IDamage)); d.TakeDamage(bulletPower); Destroy(this.gameObject); } }
void OnTriggerEnter2D(Collider2D col) { if (col.tag.Equals("Player")) { IDamage d = (IDamage)col.gameObject.GetComponent(typeof(IDamage)); d.TakeDamage(HitValueToPlayer); Destroy(gameObject); } }
void FixedUpdate() { transform.rotation = Quaternion.LookRotation(Vector3.forward, velocity); float distance = raycastDistance; //transform.rotation = Quaternion.Euler( new Vector3( 0, 0, Mathf.Rad2Deg * Mathf.Atan2( velocity.normalized.y, velocity.normalized.x ) ) ); hitCount = Physics2D.CircleCastNonAlloc(transform.position, beamRadius, velocity, RaycastHits, raycastDistance, Global.DefaultProjectileCollideLayers); for (int i = 0; i < hitCount; i++) { hit = RaycastHits[i]; if (hit.transform != null && !ignore.Contains(hit.transform) && !ignore.Contains(hit.transform)) { /* * float f = 0; * int i = 0; * for(; f <= distance; f+=1.0f, i++ ) * { * Light light = null; * if( lights.Count <= (int)i ) * { * GameObject go = Instantiate( lightPrefab, transform.position, Quaternion.identity, transform ); * light = go.GetComponent<Light>(); * lights.Add( light ); * } * light.transform.position = transform.position + (Vector3)velocity * f; * } * for( int asdf = i; asdf < lights.Count; asdf++ ) * { * lights.RemoveAt( lights.Count - 1 ); * } */ if (instigator == null || !hit.transform.IsChildOf(instigator.transform)) { IDamage dam = hit.transform.GetComponent <IDamage>(); if (dam != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = instigator; dmg.damageSource = transform; dmg.point = hit.point; if (dam.TakeDamage(dmg)) { Hit(hit.point); } } else { distance = Mathf.Min(distance, Vector2.Distance(hit.point, transform.position)); Hit(hit.point); } } } } renderer.size = new Vector2(0.2f, distance); }
void MechHit() { if (ContactDamage == null) { return; } // body hit hitCount = Physics2D.BoxCastNonAlloc(body.position, box.size, 0, velocity, RaycastHits, raylength, Global.CharacterDamageLayers); for (int i = 0; i < hitCount; i++) { hit = RaycastHits[i]; IDamage dam = hit.transform.GetComponent <IDamage>(); if (dam != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = this; dmg.damageSource = transform; dmg.point = hit.point; dam.TakeDamage(dmg); } } hitCount = Physics2D.BoxCastNonAlloc(torso.transform.position, torso.size, 0, velocity, RaycastHits, raylength, Global.CharacterDamageLayers); for (int i = 0; i < hitCount; i++) { hit = RaycastHits[i]; IDamage dam = hit.transform.GetComponent <IDamage>(); if (dam != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = this; dmg.damageSource = transform; dmg.point = hit.point; dam.TakeDamage(dmg); } } // fist hit hitCount = Physics2D.BoxCastNonAlloc(fist.transform.position, fist.size, 0, Vector2.zero, RaycastHits, raylength, Global.CharacterDamageLayers); for (int i = 0; i < hitCount; i++) { hit = RaycastHits[i]; IDamage dam = hit.transform.GetComponent <IDamage>(); if (dam != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = this; dmg.damageSource = transform; dmg.point = hit.point; dam.TakeDamage(dmg); } } }
public void OnTriggerEnter(Collider other) { if (other.tag == "Enemy") { IDamage DamRef = other.GetComponent <IDamage>(); if (DamRef != null) { if (!HasHit) { DamRef.TakeDamage(SkillManager.Instance.MagicDamage); DamRef.SetDamageText(SkillManager.Instance.MagicDamage, false); BoltLives--; HasHit = true; } } Hit = Physics.OverlapSphere(transform.position, radius); if (BoltLives <= 0 || other.GetComponent <BaseEnemy>().IsDead) { Destroy(gameObject); } if (Enemy != null) { foreach (GameObject Target in EnemiesHit) { if (Target.name == Enemy.name && Target != null) { Destroy(gameObject); } } } if (!EnemiesHit.Contains(other.gameObject)) { EnemiesHit.Add(other.gameObject); } for (int i = 0; i < Hit.Length; i++) { if (Hit[i].tag == "Enemy" && !EnemiesHit.Contains(Hit[i].gameObject)) { Enemy = Hit[i].gameObject; HasHit = false; break; } } } if (other.tag == "Wall") { Destroy(gameObject); } }
private void OnTriggerEnter(Collider other) { if (other.tag == "Player" || other.tag == "Enemy") { IDamage damage = other.GetComponent <IDamage>(); if (damage != null) { damage.TakeDamage(EnemyRef.RangedDamage); Destroy(gameObject); } } if (other.tag == "Wall") { Destroy(gameObject); } }
public void OnTriggerEnter(Collider other) { if (other.tag == "Enemy") { IDamage DamRef = other.GetComponent <IDamage>(); if (DamRef != null) { DamRef.TakeDamage(SkillManager.Instance.MagicDamage); DamRef.SetDamageText(SkillManager.Instance.MagicDamage, false); } Destroy(gameObject); } if (other.tag == "Wall") { Destroy(gameObject); } }
void FixedUpdate() { if (AlignRotationToVelocity) { transform.rotation = Quaternion.Euler(new Vector3(0, 0, Mathf.Rad2Deg * Mathf.Atan2(velocity.normalized.y, velocity.normalized.x))); } hitCount = Physics2D.CircleCastNonAlloc(transform.position, circle.radius, velocity, RaycastHits, raycastDistance, Global.DefaultProjectileCollideLayers); for (int i = 0; i < hitCount; i++) { hit = RaycastHits[i]; if (hit.transform != null && (instigator == null || !hit.transform.IsChildOf(instigator.transform)) && !ignore.Contains(hit.transform)) { IDamage dam = hit.transform.GetComponent <IDamage>(); if (dam != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = instigator; dmg.damageSource = transform; dmg.point = hit.point; if (dam.TakeDamage(dmg)) { HitCount++; if (HitCount >= DieAfterHitCount) { Hit(hit.point); return; } } } else { Hit(hit.point); return; } } } transform.position += (Vector3)velocity * Time.fixedDeltaTime; /*SpriteRenderer sr = GetComponent<SpriteRenderer>(); * sr.color = Global.instance.shiftyColor; * light.color = Global.instance.shiftyColor;*/ }
protected void BoxHit() { if (ContactDamage != null) { hitCount = Physics2D.BoxCastNonAlloc(body.position, box.size, 0, velocity, RaycastHits, raylength, Global.CharacterDamageLayers); for (int i = 0; i < hitCount; i++) { hit = RaycastHits[i]; IDamage dam = hit.transform.GetComponent <IDamage>(); if (dam != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = this; dmg.damageSource = transform; dmg.point = hit.point; dam.TakeDamage(dmg); } } } }
private void OnTriggerEnter(Collider other) { if (other.tag == "Enemy") { EnemyRef = other.GetComponent <BaseEnemy>(); EnemyRef = other.GetComponent <BaseEnemy>(); if (!EnemyRef.Attacked) { EnemiesHit.Add(other.GetComponent <BaseEnemy>()); EnemyRef.Attacked = true; IDamage DamRef = other.GetComponent <IDamage>(); if (DamRef != null) { DamRef.TakeDamage(SkillManager.Instance.AOEDamage); DamRef.SetDamageText(SkillManager.Instance.AOEDamage, false); } EnemyRef.DamEffect(DamageEffects.FireEffect); StartCoroutine(ResetAttacked()); } } }
void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; //new raycast Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //direct raycast from camera to mouse position if (Physics.Raycast(ray, out hit)) { Transform objectHit = hit.transform; // Debug.Log(objectHit.name); MonoBehaviour[] mono; //To go through every monobehavior mono = objectHit.gameObject.GetComponents <MonoBehaviour>(); if (hit.collider.gameObject.tag == "Crate") { soundSource.PlayOneShot(hitCrateSound); } else if (hit.collider.gameObject.tag == "Enemy") { soundSource.PlayOneShot(hitEnemySound); } foreach (MonoBehaviour item in mono) { if (item is IDamage) //if the item is of IDamage { IDamage temp = item as IDamage; temp.TakeDamage(); return; } } } } }
private void OnTriggerEnter(Collider other) { if (other.tag != "Enemy" || IsEnemy) { if (CanDamage) { if (CanSwing) { IDamage damageInterface = other.GetComponent <IDamage>(); if (damageInterface != null) { damageInterface.TakeDamage(Damage); damageInterface.SetDamageText(Damage, Crit); CanSwing = false; } } } else { CanDamage = true; // INCASE THE PLAYER HITS THE PET } } }
void FixedUpdate() { hitCount = Physics2D.CircleCastNonAlloc(transform.position, circle.radius + radiusFudge, velocity, RaycastHits, raycastDistance, Global.DamageCollideLayers); for (int i = 0; i < hitCount; i++) { hit = RaycastHits[i]; if (hit.transform != null && (instigator == null || !hit.transform.IsChildOf(instigator.transform)) && !ignore.Contains(hit.transform)) { IDamage dam = hit.transform.GetComponent <IDamage>(); if (dam != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = instigator; dmg.damageSource = transform; dmg.point = hit.point; if (dam.TakeDamage(dmg)) { Boom(); } break; } } } }
void CircleHit() { if (ContactDamage != null) { hitCount = Physics2D.CircleCastNonAlloc(body.position, circle.radius, body.velocity, RaycastHits, raylength, Global.CharacterDamageLayers); for (int i = 0; i < hitCount; i++) { if (RaycastHits[i].transform.GetInstanceID() == transform.GetInstanceID()) { continue; } hit = RaycastHits[i]; IDamage dam = hit.transform.GetComponent <IDamage>(); if (dam != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = this; dmg.damageSource = transform; dmg.point = hit.point; dam.TakeDamage(dmg); } } } }
new void UpdateHit(float dT) { pups.Clear(); hitCount = Physics2D.BoxCastNonAlloc(transform.position, box.size, 0, velocity, RaycastHits, Mathf.Max(raylength, velocity.magnitude * dT), HitLayers); for (int i = 0; i < hitCount; i++) { hit = RaycastHits[i]; if (hit.transform.IsChildOf(transform)) { continue; } ITrigger tri = hit.transform.GetComponent <ITrigger>(); if (tri != null) { tri.Trigger(transform); } IDamage dam = hit.transform.GetComponent <IDamage>(); if (dam != null) { // maybe only damage other if charging weapon or has active powerup? if (ContactDamage != null) { Damage dmg = Instantiate(ContactDamage); dmg.instigator = this; dmg.damageSource = transform; dmg.point = hit.point; dam.TakeDamage(dmg); } } } pups.Clear(); hitCount = Physics2D.CircleCastNonAlloc(transform.position, selectRange, Vector3.zero, RaycastHits, 0, Global.WorldSelectableLayers); for (int i = 0; i < hitCount; i++) { hit = RaycastHits[i]; IWorldSelectable pup = hit.transform.GetComponent <IWorldSelectable>(); if (pup != null) { pups.Add((Component)pup); /*if( !highlightedPickups.Contains( pup ) ) * { * pup.Highlight(); * highlightedPickups.Add( pup ); * }*/ } } //WorldSelectable closest = (WorldSelectable)FindClosest( transform.position, pups.ToArray() ); IWorldSelectable closest = (IWorldSelectable)Util.FindSmallestAngle(transform.position, shoot, pups.ToArray()); if (closest == null) { if (closestISelect != null) { closestISelect.Unhighlight(); closestISelect = null; } if (WorldSelection != null) { WorldSelection.Unselect(); WorldSelection = null; } } else if (closest != closestISelect) { if (closestISelect != null) { closestISelect.Unhighlight(); } closestISelect = closest; closestISelect.Highlight(); } /*highlightedPickupsRemove.Clear(); * foreach( var pup in highlightedPickups ) * if( !pups.Contains( pup ) ) * { * pup.Unhighlight(); * highlightedPickupsRemove.Add( pup ); * } * foreach( var pup in highlightedPickupsRemove ) * highlightedPickups.Remove( pup ); */ }
public void Hit(float damage) { mydamage.TakeDamage(damage * modifier); }
private void Attack(IDamage iDamage) { iDamage?.TakeDamage(_enemyModel.damage); }