From 4cb295785ef006b5d135ec5027069e43f8bf52f7 Mon Sep 17 00:00:00 2001 From: kittyegg Date: Tue, 19 May 2026 20:14:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D0=BF=D0=B0=D0=B2=D0=BD=20=D0=BF=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Turret.cs | 10 ++++++++-- Assets/Scripts/TurretBullet.cs | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Turret.cs b/Assets/Scripts/Turret.cs index b857900..e7dc8bb 100644 --- a/Assets/Scripts/Turret.cs +++ b/Assets/Scripts/Turret.cs @@ -1,9 +1,9 @@ -using System; using UnityEngine; public class Turret : MonoBehaviour { [SerializeField] private TurretBullet _bulletPrefab; + [SerializeField] private Transform _bulletSpawnPoint; [SerializeField] private float _reloadTime = 1f; [SerializeField] private float _damage; [SerializeField] private float _distance = 3f; @@ -15,6 +15,12 @@ public class Turret : MonoBehaviour public float Damage => _damage; public float Distance => _distance; + private void Start() + { + if (_bulletSpawnPoint == null) + _bulletSpawnPoint = transform; + } + private void Update() { SpawnBullet(Vector3.forward); @@ -30,7 +36,7 @@ public class Turret : MonoBehaviour if (_reloadTimer < _reloadTime || !DetectEnemy(direction)) return; - _bulletPrefab.Spawn(this, direction); + _bulletPrefab.Spawn(this, _bulletSpawnPoint.position, direction); _reloadTimer = 0f; } diff --git a/Assets/Scripts/TurretBullet.cs b/Assets/Scripts/TurretBullet.cs index bbfc8f8..50252ac 100644 --- a/Assets/Scripts/TurretBullet.cs +++ b/Assets/Scripts/TurretBullet.cs @@ -23,13 +23,13 @@ public class TurretBullet : MonoBehaviour Destroy(gameObject); } - public TurretBullet Spawn(Turret turret, Vector3 direction) + public TurretBullet Spawn(Turret turret, Vector3 spawnPoint, Vector3 direction) { var rot = turret.transform.rotation; rot.SetLookRotation(direction); - var bullet = Instantiate(this, turret.transform.position, rot, turret.transform); + var bullet = Instantiate(this, spawnPoint, rot, turret.transform); bullet._damage += turret.Damage; - bullet._distance += turret.Distance; + bullet._distance += turret.Distance - Vector3.Distance(spawnPoint, bullet.transform.position); return bullet; }