механики
This commit is contained in:
1 parent
dd5a95a4d3
commit
11d57bec19
129 files changed
+21889
-62
No files matched your search
@@ -0,0 +1,86 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class AmmoPickup : MonoBehaviour
|
||||
{
|
||||
[Header("Настройки")]
|
||||
public int ammoAmount = 14; // Сколько патронов дает коробка
|
||||
public bool pickupOnTouch = true; // Подбирать автоматически при касании
|
||||
public float interactionDistance = 2.5f; // Дистанция для подбора по клавише E
|
||||
public AudioClip pickupSound; // Звук подбора
|
||||
|
||||
[Header("Анимация парения")]
|
||||
public bool animateBobbing = true;
|
||||
public float rotationSpeed = 45f;
|
||||
public float bobSpeed = 2f;
|
||||
public float bobHeight = 0.1f;
|
||||
|
||||
private Vector3 startPos;
|
||||
private bool isCollected = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
startPos = transform.position;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isCollected) return;
|
||||
|
||||
// Анимация вращения и легкого покачивания
|
||||
if (animateBobbing)
|
||||
{
|
||||
transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime, Space.World);
|
||||
float newY = startPos.y + Mathf.Sin(Time.time * bobSpeed) * bobHeight;
|
||||
transform.position = new Vector3(startPos.x, newY, startPos.z);
|
||||
}
|
||||
|
||||
// Если не автоматический подбор, проверяем дистанцию до игрока и нажатие клавиши E
|
||||
if (!pickupOnTouch && Keyboard.current != null && Keyboard.current.eKey.wasPressedThisFrame)
|
||||
{
|
||||
var playerGun = FindAnyObjectByType<PlayerGun>();
|
||||
if (playerGun != null)
|
||||
{
|
||||
float dist = Vector3.Distance(transform.position, playerGun.transform.position);
|
||||
if (dist <= interactionDistance)
|
||||
{
|
||||
TryPickup(playerGun);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (isCollected || !pickupOnTouch) return;
|
||||
|
||||
PlayerGun playerGun = other.GetComponentInParent<PlayerGun>();
|
||||
if (playerGun != null)
|
||||
{
|
||||
TryPickup(playerGun);
|
||||
}
|
||||
}
|
||||
|
||||
private void TryPickup(PlayerGun playerGun)
|
||||
{
|
||||
if (playerGun == null) return;
|
||||
|
||||
bool added = playerGun.AddAmmo(ammoAmount);
|
||||
if (added)
|
||||
{
|
||||
isCollected = true;
|
||||
|
||||
if (pickupSound != null)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(pickupSound, transform.position, 1.0f);
|
||||
}
|
||||
|
||||
Debug.Log($"<color=green>[Подбор] Взята коробка патронов (+{ammoAmount})!</color>");
|
||||
Destroy(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("[Подбор] Боезапас уже полон!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user