Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

how to play sound clip when near an AI?

Discussion in 'Scripting' started by luhjgh, Oct 1, 2011.

  1. luhjgh

    luhjgh

    Joined:
    Jan 1, 2011
    Posts:
    128
    Its probably pretty simple, but I'm just wondering what function you would use for this.
     
  2. dart

    dart

    Joined:
    Jan 9, 2010
    Posts:
    211
    Find the distance from your AI object and then play the sound.

    Code (csharp):
    1.  
    2. float dist = Vector3.Distance(transform.position, ai.transform.position);
    3.  
    4. if (dist <= someValue)
    5. {
    6.    // Play the sound
    7. }
    8.  
    I assume ai is a GameObject that stores the object you call AI.