62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class PlayerNoise : MonoBehaviour
|
|
{
|
|
[Header("Радиус шума от шагов")]
|
|
public float sneakRadius = 3f;
|
|
public float walkRadius = 8f;
|
|
public float runRadius = 18f;
|
|
|
|
[Header("Настройки генерации")]
|
|
public float stepInterval = 0.5f;
|
|
private float stepTimer = 0f;
|
|
|
|
public GameObject wavePrefab;
|
|
|
|
void Update()
|
|
{
|
|
if (Keyboard.current == null) return;
|
|
|
|
bool isMoving = Keyboard.current.wKey.isPressed ||
|
|
Keyboard.current.aKey.isPressed ||
|
|
Keyboard.current.sKey.isPressed ||
|
|
Keyboard.current.dKey.isPressed;
|
|
|
|
if (isMoving)
|
|
{
|
|
stepTimer -= Time.deltaTime;
|
|
if (stepTimer <= 0f)
|
|
{
|
|
EmitStepNoise();
|
|
stepTimer = stepInterval;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
stepTimer = 0f;
|
|
}
|
|
}
|
|
|
|
private void EmitStepNoise()
|
|
{
|
|
float currentRadius = walkRadius;
|
|
|
|
if (Keyboard.current.leftShiftKey.isPressed) currentRadius = runRadius;
|
|
else if (Keyboard.current.leftCtrlKey.isPressed || Keyboard.current.cKey.isPressed) currentRadius = sneakRadius;
|
|
|
|
if (wavePrefab != null)
|
|
{
|
|
Vector3 footPosition = transform.position - new Vector3(0, transform.localScale.y / 2, 0);
|
|
Instantiate(wavePrefab, footPosition, Quaternion.identity);
|
|
}
|
|
|
|
Collider[] colliders = Physics.OverlapSphere(transform.position, currentRadius);
|
|
|
|
foreach (Collider hit in colliders)
|
|
{
|
|
BlindMutantAI mutant = hit.GetComponent<BlindMutantAI>();
|
|
if (mutant != null) mutant.HearSound(transform.position);
|
|
}
|
|
}
|
|
} |