public void Attack(AttackParameters attackDescription) { // can we attack again ? if (IsCooldownOver()) { if (ExecuteAttack(attackDescription)) { _lastAttackTime = Time.time; } } }
protected override bool ExecuteAttack(AttackParameters attackDescription) { // is the target in range ? if (IsInRange(attackDescription._target)) { attackDescription._target.SendMessage(MessageNames.OnDamage, _damage); return(true); } return(false); }
/// <summary> /// Override from WeaponBase outlining what is meant to happen, in this case a bullet /// will be spawned in the direction indicated by the attackDescription. /// </summary> /// <param name="attackDescription"></param> /// <returns></returns> protected override bool ExecuteAttack(AttackParameters attackDescription) { if (_bullets == 0) { return(false); } var bullet = Instantiate <GameObject>(_bulletPrefab); bullet.transform.localScale *= _bulletScale; bullet.transform.position = transform.position; bullet.name = "bullet " + gameObject.name; var bulletSettings = bullet.GetComponent <BulletBehaviour>(); var levelScale = _gameState == null ? 1.0f : _gameState._levelScale; bulletSettings._friendlyTag = gameObject.tag; bulletSettings._velocity = _bulletSpeed + levelScale * _speedScalingPerLevel; bulletSettings._direction = attackDescription._direction; bulletSettings._lifetime = _bulletLifeTime; bulletSettings._damage = _damage; bulletSettings._maxRange = _range; if (attackDescription._direction != Vector3.zero) { float angle = Mathf.Atan2(attackDescription._direction.y, attackDescription._direction.x) * Mathf.Rad2Deg; bullet.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); } if (_bullets > -1) { _bullets--; if (_bullets == 0 && _destroyWhenOutOfBullets) { if (transform.parent != null) { transform.parent.gameObject.SendMessage(MessageNames.OnWeaponDestroyed); } GameObject.Destroy(gameObject); } } return(true); }
// to be implemented by subclasses protected abstract bool ExecuteAttack(AttackParameters attackDescription);