2024-04-06 18:30:26 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2024-04-07 03:38:32 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
using Utility;
|
|
|
|
|
2024-04-06 18:30:26 +02:00
|
|
|
public class Zombie : MonoBehaviour
|
|
|
|
{
|
2024-04-07 03:38:32 +02:00
|
|
|
[SerializeField]
|
|
|
|
List<AudioClip> Noises;
|
|
|
|
[SerializeField]
|
|
|
|
public float speed = 5f;
|
|
|
|
[SerializeField]
|
|
|
|
private float _noiseDelay = 5.0f;
|
|
|
|
[SerializeField, ShowOnly]
|
|
|
|
private float _noiseTimer;
|
|
|
|
|
|
|
|
private Rigidbody _rb;
|
|
|
|
private AudioSource _audioSource;
|
|
|
|
private bool _fadeOutNoise = false;
|
|
|
|
|
2024-04-06 18:30:26 +02:00
|
|
|
void Start()
|
|
|
|
{
|
2024-04-07 03:38:32 +02:00
|
|
|
_rb = GetComponent<Rigidbody>();
|
|
|
|
_noiseTimer = Random.Range(0.3f * _noiseDelay, 1.5f * _noiseDelay);
|
|
|
|
_audioSource = GetComponent<AudioSource>();
|
2024-04-06 18:30:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
{
|
2024-04-07 03:38:32 +02:00
|
|
|
UpdateNoise();
|
|
|
|
MoveTowardsPlayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void MoveTowardsPlayer()
|
|
|
|
{
|
|
|
|
Vector3 direction = (GameManager.Instance.Player.transform.position - transform.position).normalized;
|
|
|
|
_rb.MovePosition(_rb.position + direction * speed * Time.deltaTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateNoise()
|
|
|
|
{
|
|
|
|
if (!_fadeOutNoise)
|
|
|
|
{
|
|
|
|
_noiseTimer -= Time.deltaTime;
|
|
|
|
|
|
|
|
if (_noiseTimer < 0)
|
|
|
|
{
|
|
|
|
_noiseTimer = _noiseDelay;
|
|
|
|
PlayRandomNoise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_audioSource.volume -= _audioSource.volume * Time.deltaTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PlayRandomNoise()
|
|
|
|
{
|
|
|
|
if (!_audioSource.isPlaying)
|
|
|
|
{
|
|
|
|
_audioSource.clip = Noises[Random.Range(0, Noises.Count)];
|
|
|
|
_audioSource.Play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void FadeOutNoise()
|
|
|
|
{
|
|
|
|
_fadeOutNoise = true;
|
2024-04-06 18:30:26 +02:00
|
|
|
}
|
|
|
|
}
|
2024-04-07 03:38:32 +02:00
|
|
|
|
|
|
|
|