то же самое
This commit is contained in:
1 parent
090cdc9933
commit
ac99977be3
534 files changed
+36990
-48
No files matched your search
@@ -1,7 +1,55 @@
|
||||
namespace DefaultNamespace
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class BlindMutantAI : MonoBehaviour
|
||||
{
|
||||
public class BlindMutantAI
|
||||
private NavMeshAgent agent;
|
||||
|
||||
[Header("Настройки скорости")]
|
||||
public float walkSpeed = 2f;
|
||||
public float runSpeed = 5f;
|
||||
|
||||
[Header("Патрулирование")]
|
||||
public Transform[] patrolPoints;
|
||||
private int currentPatrolIndex;
|
||||
private bool isInvestigating = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
agent.speed = walkSpeed;
|
||||
|
||||
if (patrolPoints.Length > 0) GoToNextPatrolPoint();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!agent.pathPending && agent.remainingDistance < 0.5f)
|
||||
{
|
||||
if (isInvestigating)
|
||||
{
|
||||
isInvestigating = false;
|
||||
agent.speed = walkSpeed;
|
||||
if (patrolPoints.Length > 0) GoToNextPatrolPoint();
|
||||
}
|
||||
else if (patrolPoints.Length > 0)
|
||||
{
|
||||
GoToNextPatrolPoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GoToNextPatrolPoint()
|
||||
{
|
||||
if (patrolPoints.Length == 0) return;
|
||||
agent.destination = patrolPoints[currentPatrolIndex].position;
|
||||
currentPatrolIndex = (currentPatrolIndex + 1) % patrolPoints.Length;
|
||||
}
|
||||
|
||||
public void HearSound(Vector3 soundPosition)
|
||||
{
|
||||
isInvestigating = true;
|
||||
agent.speed = runSpeed;
|
||||
agent.SetDestination(soundPosition);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class EchoTrigger : MonoBehaviour
|
||||
@@ -27,9 +27,16 @@ public class EchoTrigger : MonoBehaviour
|
||||
private float[] waveIntensities = new float[MAX_WAVES]; // Память для яркости каждой волны
|
||||
private bool[] waveActive = new bool[MAX_WAVES];
|
||||
|
||||
public static EchoTrigger Instance;
|
||||
|
||||
private Vector3 lastPosition;
|
||||
private float distanceMoved = 0f;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null) Instance = this;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (echoMaterial != null)
|
||||
@@ -103,6 +110,11 @@ public class EchoTrigger : MonoBehaviour
|
||||
targetIntensity = sneakIntensity;
|
||||
}
|
||||
|
||||
TriggerExternalWave(transform.position, targetMax, targetIntensity);
|
||||
}
|
||||
|
||||
public void TriggerExternalWave(Vector3 position, float targetMax, float targetIntensity)
|
||||
{
|
||||
// Ищем свободный слот
|
||||
int waveIndex = -1;
|
||||
for (int i = 0; i < MAX_WAVES; i++)
|
||||
@@ -135,6 +147,6 @@ public class EchoTrigger : MonoBehaviour
|
||||
waveActive[waveIndex] = true;
|
||||
|
||||
echoMaterial.SetFloat("_EchoOpacity" + (waveIndex + 1), targetIntensity);
|
||||
echoMaterial.SetVector("_EchoPosition" + (waveIndex + 1), transform.position);
|
||||
echoMaterial.SetVector("_EchoPosition" + (waveIndex + 1), position);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,55 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
public class ImpactWave : MonoBehaviour
|
||||
{
|
||||
[Header("Настройки эхолокации")]
|
||||
[Tooltip("Минимальная сила удара, при которой появится волна")]
|
||||
public float minImpactForce = 2f;
|
||||
|
||||
|
||||
[Tooltip("Префаб звуковой волны (или источника света)")]
|
||||
public GameObject wavePrefab;
|
||||
|
||||
[Header("Настройки слуха врагов")]
|
||||
[Tooltip("Радиус, в котором мутанты услышат падение предмета")]
|
||||
public float soundRadius = 15f;
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
// Эта строчка выведет сообщение красным текстом в консоль Unity при любом касании
|
||||
Debug.Log("УДАР! Сила: " + collision.relativeVelocity.magnitude);
|
||||
|
||||
if (collision.relativeVelocity.magnitude >= minImpactForce && wavePrefab != null)
|
||||
{
|
||||
Instantiate(wavePrefab, collision.contacts[0].point, Quaternion.identity);
|
||||
}
|
||||
// Считаем силу, с которой предмет врезался в препятствие
|
||||
float impactForce = collision.relativeVelocity.magnitude;
|
||||
Debug.Log("УДАР! Сила: " + impactForce);
|
||||
|
||||
if (impactForce >= minImpactForce)
|
||||
{
|
||||
// Берем конкретную точку в пространстве, где произошло касание
|
||||
ContactPoint contact = collision.contacts[0];
|
||||
|
||||
// Если префаб назначен, создаем его в точке удара
|
||||
// 1. ТВОЯ ЛОГИКА: Отрисовка света и волны через EchoTrigger
|
||||
if (wavePrefab != null)
|
||||
{
|
||||
Instantiate(wavePrefab, contact.point, Quaternion.identity);
|
||||
}
|
||||
|
||||
// Подсказка: если у предмета есть компонент AudioSource,
|
||||
// здесь можно вызывать звук падения, громкость которого зависит от impactForce
|
||||
if (EchoTrigger.Instance != null)
|
||||
{
|
||||
// Вычисляем интенсивность и радиус волны в зависимости от силы удара
|
||||
float intensity = Mathf.Clamp(impactForce / 5f, 0.5f, 3.0f);
|
||||
float radius = Mathf.Clamp(impactForce * 2f, 5f, 25f);
|
||||
|
||||
EchoTrigger.Instance.TriggerExternalWave(contact.point, radius, intensity);
|
||||
}
|
||||
|
||||
// 2. НОВАЯ ЛОГИКА: Оповещение мутантов о шуме
|
||||
Collider[] colliders = Physics.OverlapSphere(contact.point, soundRadius);
|
||||
|
||||
foreach (Collider hit in colliders)
|
||||
{
|
||||
BlindMutantAI mutant = hit.GetComponent<BlindMutantAI>();
|
||||
|
||||
if (mutant != null)
|
||||
{
|
||||
// Заставляем мутанта бежать в точку удара
|
||||
mutant.HearSound(contact.point);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,21 @@
|
||||
namespace DefaultNamespace
|
||||
using UnityEngine;
|
||||
|
||||
public class MutantHealth : MonoBehaviour
|
||||
{
|
||||
public class MutantHealth
|
||||
public float maxHealth = 50f;
|
||||
private float currentHealth;
|
||||
|
||||
void Start() { currentHealth = maxHealth; }
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
currentHealth -= damage;
|
||||
Debug.Log("Мутант получил урон! Осталось: " + currentHealth);
|
||||
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
Debug.Log("МУТАНТ УМЕР!");
|
||||
Destroy(gameObject); // Уничтожаем модельку мутанта
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,21 @@
|
||||
namespace DefaultNamespace
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerHealth : MonoBehaviour
|
||||
{
|
||||
public class PlayerHealth
|
||||
public float maxHealth = 100f;
|
||||
private float currentHealth;
|
||||
|
||||
void Start() { currentHealth = maxHealth; }
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
currentHealth -= damage;
|
||||
Debug.Log("Игрок получил урон! Осталось здоровья: " + currentHealth);
|
||||
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
Debug.Log("ИГРОК МЕРТВ! Конец игры.");
|
||||
// Здесь позже можно будет добавить перезагрузку уровня
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,62 @@
|
||||
namespace DefaultNamespace
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerNoise : MonoBehaviour
|
||||
{
|
||||
public class PlayerNoise
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user