From f7f06e808f66c8802ab728c2049344d1b1a9f55b Mon Sep 17 00:00:00 2001 From: kittyegg Date: Mon, 18 May 2026 19:53:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Turret.cs | 8 ++++---- Assets/Scripts/TurretBullet.cs | 13 ++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Turret.cs b/Assets/Scripts/Turret.cs index f0867c1..b857900 100644 --- a/Assets/Scripts/Turret.cs +++ b/Assets/Scripts/Turret.cs @@ -6,12 +6,14 @@ public class Turret : MonoBehaviour [SerializeField] private TurretBullet _bulletPrefab; [SerializeField] private float _reloadTime = 1f; [SerializeField] private float _damage; - [SerializeField] private float _distance; + [SerializeField] private float _distance = 3f; [SerializeField] private int _price; private float _reloadTimer; public int Price => _price; + public float Damage => _damage; + public float Distance => _distance; private void Update() { @@ -28,9 +30,7 @@ public class Turret : MonoBehaviour if (_reloadTimer < _reloadTime || !DetectEnemy(direction)) return; - var rot = transform.rotation; - rot.SetLookRotation(direction); - Instantiate(_bulletPrefab, transform.position, rot, transform); + _bulletPrefab.Spawn(this, direction); _reloadTimer = 0f; } diff --git a/Assets/Scripts/TurretBullet.cs b/Assets/Scripts/TurretBullet.cs index b1538e4..bbfc8f8 100644 --- a/Assets/Scripts/TurretBullet.cs +++ b/Assets/Scripts/TurretBullet.cs @@ -4,7 +4,7 @@ public class TurretBullet : MonoBehaviour { [SerializeField] private float _damage = 1f; [SerializeField] private float _speed = 5f; - [SerializeField] private float _distance = 3f; + [SerializeField] private float _distance; private Vector3 _spawnPos; @@ -22,4 +22,15 @@ public class TurretBullet : MonoBehaviour if (Vector3.Distance(transform.position, _spawnPos) > _distance) Destroy(gameObject); } + + public TurretBullet Spawn(Turret turret, Vector3 direction) + { + var rot = turret.transform.rotation; + rot.SetLookRotation(direction); + var bullet = Instantiate(this, turret.transform.position, rot, turret.transform); + bullet._damage += turret.Damage; + bullet._distance += turret.Distance; + + return bullet; + } }