Есть классы, есть двери, есть механика вселения, свага есть
This commit is contained in:
1 parent
2ae795c30a
commit
0f9a539460
69 files changed
+3960
-299
No files matched your search
@@ -5,13 +5,9 @@ namespace _Project.Scripts.PlayerUtils
|
||||
{
|
||||
public class PlayerCombat : MonoBehaviour
|
||||
{
|
||||
[Header("Оружие и Стрельба (Hitscan)")]
|
||||
[SerializeField] private float damage = 25f;
|
||||
[SerializeField] private float fireRate = 0.12f;
|
||||
[SerializeField] private float weaponRange = 100f;
|
||||
[Header("Оружие и Стрельба (Projectiles)")]
|
||||
[SerializeField] private bool canShoot = true;
|
||||
[SerializeField] private LayerMask hitLayers = ~0;
|
||||
[SerializeField] private bool isAutomatic = true;
|
||||
[SerializeField] private float recoilKick = 1.2f;
|
||||
|
||||
[Header("Эффекты (без звука)")]
|
||||
[SerializeField] private ParticleSystem muzzleFlash;
|
||||
@@ -21,6 +17,7 @@ namespace _Project.Scripts.PlayerUtils
|
||||
[SerializeField] private Transform cameraPosition;
|
||||
|
||||
private PlayerControls controls;
|
||||
private BodyProfile currentProfile;
|
||||
private float shootTimer = 0f;
|
||||
private bool isShootingInput = false;
|
||||
|
||||
@@ -32,45 +29,51 @@ namespace _Project.Scripts.PlayerUtils
|
||||
controls.Player.Attack.canceled += _ => isShootingInput = false;
|
||||
}
|
||||
|
||||
public void ApplyProfile(BodyProfile profile)
|
||||
{
|
||||
currentProfile = profile;
|
||||
canShoot = profile.canShoot;
|
||||
shootTimer = 0f;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (shootTimer > 0f) shootTimer -= Time.deltaTime;
|
||||
if (shootTimer > 0f) shootTimer -= Time.unscaledDeltaTime;
|
||||
if (!canShoot || currentProfile == null) return;
|
||||
|
||||
bool shootPressed = isShootingInput || (Mouse.current != null && (isAutomatic ? Mouse.current.leftButton.isPressed : Mouse.current.leftButton.wasPressedThisFrame));
|
||||
bool isAuto = currentProfile.isAutomatic;
|
||||
bool shootPressed = isShootingInput || (Mouse.current != null && (isAuto ? Mouse.current.leftButton.isPressed : Mouse.current.leftButton.wasPressedThisFrame));
|
||||
|
||||
if (shootPressed && shootTimer <= 0f)
|
||||
{
|
||||
Shoot();
|
||||
if (!isAuto) isShootingInput = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Shoot()
|
||||
{
|
||||
shootTimer = fireRate;
|
||||
shootTimer = currentProfile.fireRate;
|
||||
|
||||
// ВЫЗОВ ЗВУКА ИЗ НОВОГО МОДУЛЯ
|
||||
Player.Instance.Sound.PlayShoot();
|
||||
|
||||
if (muzzleFlash != null) muzzleFlash.Play();
|
||||
Player.Instance.CameraController.ApplyRecoil(recoilKick);
|
||||
Player.Instance.CameraController.ApplyRecoil(currentProfile.recoilKick);
|
||||
|
||||
Ray ray = new Ray(cameraPosition.position, cameraPosition.forward);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, weaponRange, hitLayers, QueryTriggerInteraction.Ignore))
|
||||
int pellets = Mathf.Max(1, currentProfile.pelletsPerShot);
|
||||
float spread = currentProfile.spreadAngle;
|
||||
Vector3 spawnPos = cameraPosition.position + cameraPosition.forward * 0.6f - cameraPosition.up * 0.1f;
|
||||
|
||||
for (int i = 0; i < pellets; i++)
|
||||
{
|
||||
if (hit.collider.TryGetComponent<IDamageable>(out var damageable))
|
||||
Vector3 dir = cameraPosition.forward;
|
||||
if (spread > 0.01f)
|
||||
{
|
||||
damageable.TakeDamage(damage);
|
||||
}
|
||||
else if (hit.rigidbody != null)
|
||||
{
|
||||
hit.rigidbody.AddForceAtPosition(-hit.normal * (damage * 10f), hit.point, ForceMode.Impulse);
|
||||
dir = Quaternion.Euler(
|
||||
Random.Range(-spread, spread),
|
||||
Random.Range(-spread, spread), 0f) * dir;
|
||||
}
|
||||
|
||||
if (impactPrefab != null)
|
||||
{
|
||||
GameObject impact = Instantiate(impactPrefab, hit.point + (hit.normal * 0.001f), Quaternion.LookRotation(hit.normal));
|
||||
Destroy(impact, 3f);
|
||||
}
|
||||
Projectile.Spawn(spawnPos, dir, currentProfile, true, gameObject, hitLayers, impactPrefab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user