крутой шейдер

This commit is contained in:
lapich committed 2026-10-21 13:53:17 +03:00
1 parent da648df1d9
commit 9245409fc9
9 files changed
+446 -59

No files matched your search

+110 -20
View File
@@ -12,6 +12,9 @@ public class BlindMutantAI : MonoBehaviour
[Header("Патрулирование")]
public Transform[] patrolPoints;
[Tooltip("Время паузы на точке патрулирования для прислушивания")]
public float waitTimeAtPoint = 1.5f;
private float waitTimer = 0f;
private int currentPatrolIndex;
private bool isInvestigating = false;
@@ -30,7 +33,20 @@ public class BlindMutantAI : MonoBehaviour
void Start()
{
agent = GetComponent<NavMeshAgent>();
agent.speed = walkSpeed;
if (agent != null)
{
agent.speed = walkSpeed;
// Если агент чуть выше пола или не на сетке, привязываем его к ближайшей точке NavMesh
if (!agent.isOnNavMesh)
{
if (NavMesh.SamplePosition(transform.position, out NavMeshHit hit, 5.0f, NavMesh.AllAreas))
{
agent.Warp(hit.position);
}
}
}
animator = GetComponentInChildren<Animator>();
// Автоматически находим игрока на сцене
@@ -40,9 +56,36 @@ public class BlindMutantAI : MonoBehaviour
targetPlayerHealth = playerObj;
}
if (patrolPoints != null && patrolPoints.Length > 0)
// Если точки патрулирования не заданы или массив состоит из null, ищем PatrolWaypoints на сцене
if (IsPatrolArrayEmptyOrNull())
{
GoToNextPatrolPoint();
AutoAssignPatrolWaypoints();
}
GoToNextPatrolPoint();
}
private bool IsPatrolArrayEmptyOrNull()
{
if (patrolPoints == null || patrolPoints.Length == 0) return true;
for (int i = 0; i < patrolPoints.Length; i++)
{
if (patrolPoints[i] != null) return false;
}
return true;
}
private void AutoAssignPatrolWaypoints()
{
var patrolRoot = GameObject.Find("PatrolWaypoints");
if (patrolRoot != null && patrolRoot.transform.childCount > 0)
{
patrolPoints = new Transform[patrolRoot.transform.childCount];
for (int i = 0; i < patrolRoot.transform.childCount; i++)
{
patrolPoints[i] = patrolRoot.transform.GetChild(i);
}
Debug.Log($"<color=cyan>[BlindMutantAI] Автоматически обнаружено {patrolPoints.Length} точек патрулирования в объекте 'PatrolWaypoints'.</color>");
}
}
@@ -67,12 +110,14 @@ public class BlindMutantAI : MonoBehaviour
private void UpdateAnimator()
{
if (animator == null) return;
float currentSpeed = agent != null && agent.enabled ? agent.velocity.magnitude : 0f;
float currentSpeed = agent != null && agent.enabled && agent.isOnNavMesh ? agent.velocity.magnitude : 0f;
animator.SetFloat("Speed", currentSpeed);
}
private void HandlePlayerChaseAndAttack()
{
if (agent == null || !agent.isOnNavMesh) return;
if (targetPlayerHealth != null && targetPlayerHealth.IsDead)
{
LosePlayerTarget();
@@ -138,26 +183,34 @@ public class BlindMutantAI : MonoBehaviour
private void HandlePatrolAndInvestigation()
{
if (!agent.pathPending && agent.remainingDistance < 0.5f)
if (agent == null || !agent.isOnNavMesh) return;
if (!agent.pathPending && agent.remainingDistance < 0.6f)
{
if (isInvestigating)
{
isInvestigating = false;
agent.speed = walkSpeed;
if (patrolPoints != null && patrolPoints.Length > 0)
{
GoToNextPatrolPoint();
}
waitTimer = waitTimeAtPoint;
}
else if (patrolPoints != null && patrolPoints.Length > 0)
if (waitTimer > 0f)
{
GoToNextPatrolPoint();
waitTimer -= Time.deltaTime;
agent.isStopped = true;
return;
}
agent.isStopped = false;
waitTimer = waitTimeAtPoint;
GoToNextPatrolPoint();
}
}
private void EngagePlayer(Transform playerTransform)
{
if (agent == null || !agent.isOnNavMesh) return;
targetPlayer = playerTransform;
if (targetPlayerHealth == null)
{
@@ -165,6 +218,7 @@ public class BlindMutantAI : MonoBehaviour
}
isInvestigating = false;
waitTimer = 0f;
agent.isStopped = false;
agent.speed = runSpeed;
agent.SetDestination(targetPlayer.position);
@@ -174,22 +228,55 @@ public class BlindMutantAI : MonoBehaviour
private void LosePlayerTarget()
{
targetPlayer = null;
agent.isStopped = false;
agent.speed = walkSpeed;
isInvestigating = false;
if (patrolPoints != null && patrolPoints.Length > 0)
if (agent != null && agent.isOnNavMesh)
{
GoToNextPatrolPoint();
agent.isStopped = false;
agent.speed = walkSpeed;
}
isInvestigating = false;
waitTimer = 0f;
GoToNextPatrolPoint();
Debug.Log("Мутант потерял игрока и возвращается к патрулированию.");
}
private void GoToNextPatrolPoint()
{
if (patrolPoints == null || patrolPoints.Length == 0) return;
agent.destination = patrolPoints[currentPatrolIndex].position;
currentPatrolIndex = (currentPatrolIndex + 1) % patrolPoints.Length;
if (agent == null || !agent.isOnNavMesh) return;
if (patrolPoints != null && patrolPoints.Length > 0)
{
for (int attempts = 0; attempts < patrolPoints.Length; attempts++)
{
var wp = patrolPoints[currentPatrolIndex];
currentPatrolIndex = (currentPatrolIndex + 1) % patrolPoints.Length;
if (wp != null)
{
agent.isStopped = false;
agent.speed = walkSpeed;
agent.SetDestination(wp.position);
return;
}
}
}
// Если точек нет вообще — свободное блуждание по комплексу
WanderRandomly();
}
private void WanderRandomly()
{
if (agent == null || !agent.isOnNavMesh) return;
Vector3 randomDir = Random.insideUnitSphere * 15f;
randomDir += transform.position;
if (NavMesh.SamplePosition(randomDir, out NavMeshHit hit, 15f, NavMesh.AllAreas))
{
agent.isStopped = false;
agent.speed = walkSpeed;
agent.SetDestination(hit.position);
}
}
public void HearSound(Vector3 soundPosition)
@@ -200,7 +287,10 @@ public class BlindMutantAI : MonoBehaviour
return;
}
if (agent == null || !agent.isOnNavMesh) return;
isInvestigating = true;
waitTimer = 0f;
agent.isStopped = false;
agent.speed = runSpeed;
agent.SetDestination(soundPosition);