SHOW:
|
|
- or go back to the newest paste.
| 1 | - | // Unity 3D example finding particular component when you have multiple of the same type |
| 1 | + | // how to find a particular AudioSource (by clip name) when you have multiple attached |
| 2 | - | // In this example, finding a particular AudioSource (by clip name) if you have multiple sources on your object |
| 2 | + | |
| 3 | function Start() {
| |
| 4 | - | var music : AudioClip; |
| 4 | + | var music : AudioClip; |
| 5 | - | for (var src in GetComponents.<AudioSource>()) {
|
| 5 | + | for (var src in GetComponents.<AudioSource>()) {
|
| 6 | - | if (src.clip.name == "music") {
|
| 6 | + | if (src.clip.name == "music") {
|
| 7 | - | music = src; |
| 7 | + | music = src; |
| 8 | - | break; |
| 8 | + | break; |
| 9 | } | |
| 10 | - | } |
| 10 | + | |
| 11 | - | music.Play(); |
| 11 | + | music.Play(); |
| 12 | } |