/// <summary> /// Наносит урон /// </summary> /// <param name="obj"></param> /// <param name="damage"></param> protected virtual void SetDamage(IDamageble obj, float damage) { if (obj != null) { obj.GetDamage(damage); } }
private void OnCollide(Collider2D collider) { IDamageble damageble = collider.GetComponent <IDamageble>(); if (damageble != null) { PlayerInputController player = collider.GetComponent <PlayerInputController>(); if (player != null) { if (!isAlliedForPlayer) { DealDamage(damageble); } } else { IEnemy enemy = collider.GetComponent <IEnemy>(); if (enemy != null) { if (!isAlliedForEnemy) { DealDamage(damageble); } } } } }
protected override void OnCantMove(IDamageble component) { var hitWall = component; hitWall.Damaged(wallDamage); _animator.SetTrigger(PlayerChop); }
private void SetDamage(IDamageble obj) { if (obj != null) { obj.TakeDamage(_damage); Destroy(gameObject); } }
private void OnPlayerAttack(IDamageble demageble) { if (demageble.ApplyDemage(_state.Rigidbody, _attackForce) == false) { return; } _state.Rigidbody.velocity /= 2; }
void OnTriggerExit(Collider other) { IDamageble pl = other.GetComponent <IDamageble>(); if (pl != null) { targetsInRadius.Remove(pl); } }
void OnCollisionEnter(Collision other) // other - любой объект с которым столкнулся { IDamageble damageble = other.gameObject.GetComponent <IDamageble>(); // gameObject - объект (куб, стена) if (damageble != null) { damageble.Damage(GetDamage()); } }
void OnHitObject(Collider c, Vector3 hitPoint) { IDamageble damagebleObject = c.GetComponent <Collider>().GetComponent <IDamageble>(); if (damagebleObject != null) { damagebleObject.TakeHit(damage, hitPoint, transform.forward); } Destroy(gameObject); }
void OnTriggerEnter2D(Collider2D col) { IDamageble <int> damagable = col.gameObject.GetComponent <IDamageble <int> >(); if (damagable != null) { damagable.Damage(damage, damageType); } Destroy(gameObject); }
void OnTriggerEnter(Collider other) { IDamageble creature = other.GetComponent <IDamageble>(); if (creature != null) { creature.Die(gameObject); Dodge.dodge.gamePlayers.Remove(other.gameObject); } }
void OnTriggerEnter(Collider other) { IDamageble pl = other.GetComponent <IDamageble>(); if (pl != null) { if (!targetsInRadius.Contains(pl)) { targetsInRadius.Add(pl); } } }
protected override void OnCantMove(IDamageble component) { if (!(component is Player)) { return; } component.Damaged(playerDamage); _animator.SetTrigger(EnemyAttack); SoundManager.instance.RandomizeSfx(enemyAttack2); }
private void OnCollide(Collider2D collider) { IDamageble damageble = collider.GetComponent <IDamageble>(); if (damageble != null) { PlayerInputController player = collider.GetComponent <PlayerInputController>(); if (player != null) { DealDamage(damageble); } } }
void OnTriggerEnter2D(Collider2D other) { PlayerController player = other.GetComponent <PlayerController>(); if (player != null) { IDamageble targetDamage = other.GetComponent <IDamageble>(); if (targetDamage != null) { targetDamage.TakeDamage(hitter, damage, false); } } }
public void Shooting(Vector3 _origin, Vector3 _dir, Vector3 _startBuiletPosition, float _range, GameObject _builetPref, float _damage, float _speed) { RaycastHit _hit; if (Physics.Raycast(_origin, _dir, out _hit, _range)) { GameObject outBuilett = GameObject.Instantiate(_builetPref, _startBuiletPosition, Quaternion.identity); outBuilett.GetComponent <Rigidbody>().AddForce(_current.transform.forward * _speed); IDamageble dmg = _hit.transform.GetComponent <IDamageble>(); if (dmg != null) { dmg.TakeDamage(_damage); } } }
//this is for the bullet which is inside a collider and still destroying the gameObject. void OnHiObject(Collider c) { //here first we are calling the IDamageble script //and then on what ever with the hit HITS it is checking if the hitted object having the IDamageble so it can call the TakeHit method. //since TakeHit is the method that allows the projectile to destroy. IDamageble damageObject = c.GetComponent <IDamageble>(); if (damageObject != null) { float damage = 1; damageObject.TakeDamage(damage); } //print(hit.collider.gameObject.name); GameObject.Destroy(gameObject); }
private void OnTriggerEnter2D(Collider2D collider) { IDamageble enemy = collider.transform.GetComponent <IDamageble>(); if (enemy != null && collider.transform.tag != allyTag) { enemy.GetDamage(damage); Impact(); } Debug.Log($"Collision: {collider.transform.name}"); if (collider.transform.tag != transform.tag && collider.transform.tag != "triggers") { Impact(); } }
public override void OnMouseDown(Transform cameraPos) { RaycastHit whatIHit; if (Physics.Raycast(cameraPos.position, cameraPos.forward, out whatIHit, Mathf.Infinity)) { IDamageble damageble = whatIHit.collider.GetComponent <IDamageble>(); if (damageble != null) { float normalizedDistance = whatIHit.distance / maxRange; if (normalizedDistance <= 1) { damageble.DealDamage(Mathf.RoundToInt(Mathf.Lerp(maxDamage, minDamage, normalizedDistance))); Debug.Log(whatIHit.collider.name); } } } }
void OnTriggerEnter2D(Collider2D other) { if (other.isTrigger == true) { return; } Block block = other.GetComponent <Block>(); if (weaponType != "PickAxe" && block != null) { return; } IDamageble hit = other.GetComponent <IDamageble>(); Debug.Log("IS CRIT:" + isCritical); if (hit != null) { hit.TakeDamage(GameSession.instance.Player.gameObject, damage, isCritical); } }
private void DealDamage(IDamageble damageble) { damageble.GetDamage(damage); Destroy(); }
protected abstract void OnCantMove(IDamageble component);
private void DealDamage(IDamageble damageble) { damageble.GetDamage(damage); stats.SetCurLife(0); }