0
当敌人死亡时,他播放声音,但声音最终变得超级失真。我认为这是因为它使用Update方法,但我不知道如何克服这一点。播放时声音超级失真
从其他论坛,我读过他们说要使用布尔值,但我怎么会在这种情况下执行布尔值?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.AI;
public class aiscript : MonoBehaviour
{
NavMeshAgent agent;
public GameObject bloodExplosion;
private AudioSource audioSource;
public GameObject render;
public float Health;
public GameObject bloodSpawn;
private Transform bloodSpawned;
public GameObject player;
void Start()
{
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
agent.SetDestination(player.transform.position);
if(Health <= 0)
{
render.SetActive(true);
audioSource = gameObject.GetComponent<AudioSource>();
audioSource.PlayOneShot(audioSource.clip);
Instantiate(bloodExplosion, bloodSpawn.transform.position,
bloodSpawn.transform.rotation);
Die();
}
}
public void Die()
{
Destroy(this.gameObject, audioSource.clip.length);
}
}