79 lines
2.2 KiB
C#
79 lines
2.2 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("Оружие")]
|
|
[SerializeField] private 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;
|
|
|
|
|
|
private int weaponIndex = 0;
|
|
private Weapon ActiveWeapon => weaponsContainer[weaponIndex];
|
|
|
|
void Update()
|
|
{
|
|
var targetHeight = In.GetButton(DiveSignal) ? DownPoint.position.y : UpPoint.position.y;
|
|
MoveToHeight(targetHeight);
|
|
|
|
if (In.GetButtonDown(ShootSignal))
|
|
{
|
|
Shoot();
|
|
}
|
|
if (In.GetButtonDown(ChangeWeapon))
|
|
{
|
|
NextWeapon();
|
|
}
|
|
}
|
|
|
|
private void NextWeapon()
|
|
{
|
|
print("Смена оружия");
|
|
weaponIndex = (weaponIndex + 1) % weaponsContainer.Count;
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|