Question by
julian_at_pf · Mar 15, 2018 at 11:35 AM ·
tutorialstanks
Issue with the tank tutorial health system
I'm not understanding the code:
private void Awake ()
{
// Instantiate the explosion prefab and get a reference to the particle system on it.
m_ExplosionParticles = Instantiate (m_ExplosionPrefab).GetComponent<ParticleSystem> ();
// Get a reference to the audio source on the instantiated prefab.
m_ExplosionAudio = m_ExplosionParticles.GetComponent<AudioSource> ();
// Disable the prefab so it can be activated when it's required.
m_ExplosionParticles.gameObject.SetActive (false);
}
In the first line, it's obtaining the particle system from a game object. That's cool, I understand that. But the second line then gets the audio not from the prefab where it's been set up on, but on the particle system itself, which doesn't have an AudioSource afaict? How does this work? Shouldn't the code read
var instance = Instantiate(m_ExplosionPrefab);
m_ExplosionParticles = instance.GetComponent<ParticleSystem>();
m_ExplosionAudio = instance.GetComponent<AudioSource>();
Comment
Your answer
Follow this Question
Related Questions
Tanks tutorial 'Input' issue 0 Answers
How to stop my tank from not moving??? 0 Answers
Tanks Tutorial Title 0 Answers
Animation using Mecanim tutorials 0 Answers
enemy reflection not working unity 3D survival shooter game -1 Answers