duck

Find audiosource with specific clip

Nov 6th, 2011
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Unity 3D example finding particular component when you have multiple of the same type
  2. // In this example, finding a particular AudioSource (by clip name) if you have multiple sources on your object
  3.  
  4. var music : AudioClip;
  5. for (var src in GetComponents.<AudioSource>()) {
  6.     if (src.clip.name == "music") {
  7.         music = src;
  8.         break;
  9.     }
  10. }
  11. music.Play();
Advertisement
Add Comment
Please, Sign In to add comment