Search Unity

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.