private void Update() { if (player != null && (DateTime.Now - lastEncounter).TotalSeconds > timeDelay) { player.TakeDamage(damage); lastEncounter = DateTime.Now; } }
private void Update() { if (_player != null && (DateTime.Now - _lastEncounter).TotalSeconds > _timeDelay) { _player.TakeDamage(_damage); _lastEncounter = DateTime.Now; } }
protected void Strike() { Collider2D player = Physics2D.OverlapBox(_strikePoint.position, new Vector2(_strikeRange, _strikeRange), 0, _enemies); if (player != null) { Player_controller playerControler = player.GetComponent <Player_controller>(); int damage = _damage; if (playerControler != null) { playerControler.TakeDamage(damage); } } }
protected virtual void TryToDamage(Collider2D enemy) { if ((Time.time - lastDamageTime) < collisionTimeDelay) { return; } Player_controller player = enemy.GetComponent <Player_controller>(); if (player != null) { player.TakeDamage(collisionDamage, collisionDamageType, transform); } }
private void OnTriggerEnter2D(Collider2D info) { if ((DateTime.Now - _lastEncounter).TotalSeconds < 0.1f) //добавил { return; //добавил } _lastEncounter = DateTime.Now; //добавил _player = info.GetComponent <Player_controller>(); if (_player != null) { _player.TakeDamage(_damage); } }
private void OnTriggerEnter2D(Collider2D info) { if ((DateTime.Now - lastEncounter).TotalSeconds < 0.02f) { return; } lastEncounter = DateTime.Now; player = info.GetComponent <Player_controller>(); if (player != null) { player.TakeDamage(damage, DamageType.PowerStrike, gameObject.transform); } }
private void OnTriggerEnter2D(Collider2D info) { if (Time.time - _lastEncounter < 0.1f) { return; } _lastEncounter = Time.time; Player_controller player = info.GetComponent <Player_controller>(); if (player != null) { player.TakeDamage(_damage); } Destroy(gameObject); }