mirror of
https://github.com/ryzij/Cube-Tower-Defense.git
synced 2026-07-14 01:56:57 +00:00
Изменил спавн пули
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
using System;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Turret : MonoBehaviour
|
public class Turret : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private TurretBullet _bulletPrefab;
|
[SerializeField] private TurretBullet _bulletPrefab;
|
||||||
|
[SerializeField] private Transform _bulletSpawnPoint;
|
||||||
[SerializeField] private float _reloadTime = 1f;
|
[SerializeField] private float _reloadTime = 1f;
|
||||||
[SerializeField] private float _damage;
|
[SerializeField] private float _damage;
|
||||||
[SerializeField] private float _distance = 3f;
|
[SerializeField] private float _distance = 3f;
|
||||||
@@ -15,6 +15,12 @@ public class Turret : MonoBehaviour
|
|||||||
public float Damage => _damage;
|
public float Damage => _damage;
|
||||||
public float Distance => _distance;
|
public float Distance => _distance;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
if (_bulletSpawnPoint == null)
|
||||||
|
_bulletSpawnPoint = transform;
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
SpawnBullet(Vector3.forward);
|
SpawnBullet(Vector3.forward);
|
||||||
@@ -30,7 +36,7 @@ public class Turret : MonoBehaviour
|
|||||||
if (_reloadTimer < _reloadTime || !DetectEnemy(direction))
|
if (_reloadTimer < _reloadTime || !DetectEnemy(direction))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_bulletPrefab.Spawn(this, direction);
|
_bulletPrefab.Spawn(this, _bulletSpawnPoint.position, direction);
|
||||||
_reloadTimer = 0f;
|
_reloadTimer = 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ public class TurretBullet : MonoBehaviour
|
|||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TurretBullet Spawn(Turret turret, Vector3 direction)
|
public TurretBullet Spawn(Turret turret, Vector3 spawnPoint, Vector3 direction)
|
||||||
{
|
{
|
||||||
var rot = turret.transform.rotation;
|
var rot = turret.transform.rotation;
|
||||||
rot.SetLookRotation(direction);
|
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._damage += turret.Damage;
|
||||||
bullet._distance += turret.Distance;
|
bullet._distance += turret.Distance - Vector3.Distance(spawnPoint, bullet.transform.position);
|
||||||
|
|
||||||
return bullet;
|
return bullet;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user