122 lines
3.3 KiB
C#
122 lines
3.3 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Player : MonoBehaviour
|
|
{
|
|
[Header("Управление")]
|
|
[SerializeField] private InSignal DiveSignal;
|
|
[SerializeField] private InSignal ShootSignal;
|
|
[SerializeField] private InSignal ChangeWeapon;
|
|
|
|
[Header("Оружие")]
|
|
public List<Weapon> weaponsContainer;
|
|
|
|
[Header("Настройки погружения")]
|
|
[SerializeField] private Transform UpPoint;
|
|
[SerializeField] private Transform DownPoint;
|
|
[SerializeField] private float MaxSpeed = 5f;
|
|
[SerializeField] private float SmoothTime = 0.5f; // Время разгона/торможения
|
|
|
|
private float currentHeightVelocity = 0f;
|
|
|
|
public float DepthPercent => (UpPoint.position.y - transform.position.y) / totalHeight;
|
|
|
|
|
|
public float DepthPercentToStartPressure = 0.1f;
|
|
public float PressureMultiplier = 0.2f;
|
|
public float PressurePercent { get; private set; }
|
|
|
|
|
|
|
|
public float RotationAngle { get; private set; }
|
|
|
|
|
|
private float totalHeight = 10f;
|
|
private int weaponIndex = 0;
|
|
public Weapon ActiveWeapon => weaponsContainer[weaponIndex];
|
|
|
|
private void Awake()
|
|
{
|
|
totalHeight = UpPoint.position.y - DownPoint.position.y;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (PressurePercent < 1f)
|
|
{
|
|
var targetHeight = In.GetButton(DiveSignal) ? DownPoint.position.y : UpPoint.position.y;
|
|
MoveToHeight(targetHeight);
|
|
}
|
|
else
|
|
{
|
|
var targetHeight = UpPoint.position.y;
|
|
MoveToHeight(targetHeight);
|
|
}
|
|
|
|
if (In.GetButtonDown(ShootSignal))
|
|
{
|
|
Shoot();
|
|
}
|
|
if (In.GetButtonDown(ChangeWeapon))
|
|
{
|
|
NextWeapon();
|
|
}
|
|
|
|
if (DepthPercent > DepthPercentToStartPressure)
|
|
{
|
|
AddPressure();
|
|
}
|
|
else
|
|
{
|
|
PressurePercent -= PressureMultiplier * Time.deltaTime;
|
|
}
|
|
}
|
|
|
|
private void AddPressure()
|
|
{
|
|
float pressureStrength = DepthPercent * PressureMultiplier;
|
|
PressurePercent += pressureStrength * Time.deltaTime;
|
|
PressurePercent = Mathf.Clamp01(PressurePercent);
|
|
}
|
|
|
|
private void NextWeapon()
|
|
{
|
|
print("Смена оружия");
|
|
weaponIndex = (weaponIndex + 1) % weaponsContainer.Count;
|
|
GameState.WeaponModel.WeaponChangeHandler(ActiveWeapon);
|
|
}
|
|
|
|
private void Shoot()
|
|
{
|
|
ActiveWeapon.Shoot();
|
|
}
|
|
|
|
public void MoveToHeight(float targetHeight)
|
|
{
|
|
|
|
|
|
float currentY = transform.position.y;
|
|
|
|
float newY = Mathf.SmoothDamp(
|
|
currentY,
|
|
targetHeight,
|
|
ref currentHeightVelocity,
|
|
SmoothTime,
|
|
MaxSpeed
|
|
);
|
|
|
|
Vector3 newPosition = transform.position;
|
|
newPosition.y = newY;
|
|
transform.position = newPosition;
|
|
|
|
|
|
float magnitude = UpPoint.position.y - DownPoint.position.y;
|
|
float t = (transform.position.y - DownPoint.position.y) / magnitude;
|
|
|
|
float minDensity = 0.0001f; // Минимальная плотность (на поверхности)
|
|
float maxDensity = 0.01f; // Максимальная плотность (на дне)
|
|
RenderSettings.fogDensity = Mathf.Lerp(maxDensity, minDensity, t);
|
|
}
|
|
|
|
}
|