Skip to main content
added note about sequence and fixed a typo
Source Link
Joe
  • 558
  • 4
  • 17

I can't speackspeak exactly to the specific issue you are having, but I can say I am prettyfairly certain you can add multiple of the same type of component to one GameObject. The best way I have found to do this is to access them is by using the "GetComponents" method call. Something like this should do:

AudioSource[] allMyAudioSources = GetComponents<AudioSource>();

This will return an array of AudioSources, which you can then assign to different variablevariables and access independently without freaking things out. Something like thatthis in C#:

AudioSource thrusterSource;
AudioSource guardSource;

void Start() {
    AudioSource[] allMyAudioSources = GetComponents<AudioSource>();
    thrusterSource = allMyAudioSources[0];
    guardSource = allMyAudioSources[1];
}

// These should no longer bug each other out!
guardSource.Play();
thrusterSource.Play();

EDIT: I thought it would be worth noting if it's not obvious, I have found the Components will populate the array in sequence from top to bottom. So it will help to keep that in mind when assigning those sound files.

I can't speack exactly to the specific issue you are having, but I can say I am pretty certain you can add multiple of the same type of component to one GameObject. The best way I have found to do this is to access them is by using the "GetComponents" method call.

AudioSource[] allMyAudioSources = GetComponents<AudioSource>();

This will return an array of AudioSources, which you can then assign to different variable and access independently without freaking things out. Something like that in C#:

AudioSource thrusterSource;
AudioSource guardSource;

void Start() {
    AudioSource[] allMyAudioSources = GetComponents<AudioSource>();
    thrusterSource = allMyAudioSources[0];
    guardSource = allMyAudioSources[1];
}

// These should no longer bug each other out!
guardSource.Play();
thrusterSource.Play();

I can't speak exactly to the specific issue you are having, but I can say I am fairly certain you can add multiple of the same type of component to one GameObject. The best way I have found to do this is to access them is by using the "GetComponents" method call. Something like this should do:

AudioSource[] allMyAudioSources = GetComponents<AudioSource>();

This will return an array of AudioSources, which you can then assign to different variables and access independently without freaking things out. Something like this in C#:

AudioSource thrusterSource;
AudioSource guardSource;

void Start() {
    AudioSource[] allMyAudioSources = GetComponents<AudioSource>();
    thrusterSource = allMyAudioSources[0];
    guardSource = allMyAudioSources[1];
}

// These should no longer bug each other out!
guardSource.Play();
thrusterSource.Play();

EDIT: I thought it would be worth noting if it's not obvious, I have found the Components will populate the array in sequence from top to bottom. So it will help to keep that in mind when assigning those sound files.

deleted 2 characters in body
Source Link
Joe
  • 558
  • 4
  • 17

I can't speack exactly to the specific issue you are having, but I can say I am pretty certain you can add multiple of the same type of component to one GameObject. The best way I have found to do this is to access them is by using the "GetComponents" method call.

AudioSource[] allMyAudioSources = GetComponents<AudioSource>();

This will return an array of AudioSources, which you can then assign to different variable and access independently without freaking things out. Something like that in C#:

AudioSource thrusterSource;
AudioSource guardSource;

void Start() {
    AudioSource[] allMyAudioSources = GetComponents<AudioSource>();
    thrusterSource = allMyAudioSources[0];
    guardSource = allMyAudioSources[1];
}

// theseThese should no longer freakbug each other out!
guardSource.Play();
thrusterSource.Play();

I can't speack exactly to the specific issue you are having, but I can say I am pretty certain you can add multiple of the same type of component to one GameObject. The best way I have found to do this is to access them is by using the "GetComponents" method call.

AudioSource[] allMyAudioSources = GetComponents<AudioSource>();

This will return an array of AudioSources, which you can then assign to different variable and access independently without freaking things out. Something like that in C#:

AudioSource thrusterSource;
AudioSource guardSource;

void Start() {
    AudioSource[] allMyAudioSources = GetComponents<AudioSource>();
    thrusterSource = allMyAudioSources[0];
    guardSource = allMyAudioSources[1];
}

// these should no longer freak each other out
guardSource.Play();
thrusterSource.Play();

I can't speack exactly to the specific issue you are having, but I can say I am pretty certain you can add multiple of the same type of component to one GameObject. The best way I have found to do this is to access them is by using the "GetComponents" method call.

AudioSource[] allMyAudioSources = GetComponents<AudioSource>();

This will return an array of AudioSources, which you can then assign to different variable and access independently without freaking things out. Something like that in C#:

AudioSource thrusterSource;
AudioSource guardSource;

void Start() {
    AudioSource[] allMyAudioSources = GetComponents<AudioSource>();
    thrusterSource = allMyAudioSources[0];
    guardSource = allMyAudioSources[1];
}

// These should no longer bug each other out!
guardSource.Play();
thrusterSource.Play();
Source Link
Joe
  • 558
  • 4
  • 17

I can't speack exactly to the specific issue you are having, but I can say I am pretty certain you can add multiple of the same type of component to one GameObject. The best way I have found to do this is to access them is by using the "GetComponents" method call.

AudioSource[] allMyAudioSources = GetComponents<AudioSource>();

This will return an array of AudioSources, which you can then assign to different variable and access independently without freaking things out. Something like that in C#:

AudioSource thrusterSource;
AudioSource guardSource;

void Start() {
    AudioSource[] allMyAudioSources = GetComponents<AudioSource>();
    thrusterSource = allMyAudioSources[0];
    guardSource = allMyAudioSources[1];
}

// these should no longer freak each other out
guardSource.Play();
thrusterSource.Play();