Answered
0
0

I have an enemy moving towards the player but the audio is repeated many times, that line of code missing?

enter image description here

using UnityEngine;
using System.Collections;

public class EnemyMovement : MonoBehaviour
{
Transform player;
PlayerHealth playerHealth;
EnemyHealth enemyHealth;
NavMeshAgent nav;

[FMODUnity.EventRef]
string Playerstate2 = "event:/Music";

void Awake ()
{
    player = GameObject.FindGameObjectWithTag ("Player").transform;
    playerHealth = player.GetComponent <PlayerHealth> ();
    enemyHealth = GetComponent <EnemyHealth> ();
    nav = GetComponent <NavMeshAgent> ();

}


void Update ()
{
    //FMODUnity.RuntimeManager.PlayOneShot (Playerstate2, transform.position);
    //FMODUnity.RuntimeManager.PlayOneShot(Playerstate2, GameObject); 
    Playerstate2.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject,cachedRigidBody));
    if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
    {

        nav.SetDestination (player.position);

    }
    else
    {
        nav.enabled = false;
    }

}

}

  • You must to post comments
Best Answer
0
0

If the sound is constantly repeating then you either need to look at the event in FMOD Studio, or you are constantly restarting the event in code. You haven’t shown the code that would let us determine if it’s the second case.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.