Help me with this parent-child relation.
Answer by elmax · May 24, 2017 at 11:19 AM
Transform has the option "FindChild", so you can get the particle systems' component from that.
declare this:
public ParticleSystem m_explosion;
then below that
void Awake(){
m_explosion = Transform.FindChild("Strong Aquaragia break").GetComponent<ParticleSystem>();
}
You can turn m_explosion private, but this way you can see it working in the editor.
It's also good practice NOT to use "Find" or "FindChild" constantly, like in an Update() - better grab that stuff on Awake() or Start() an use the references anywhere else.
HTH.
Answer by BaldBeardedMonk · May 24, 2017 at 11:46 AM
If the order of the gameobjects is fixed in the hierarchy. and the script is attached to the topmost gameObject as you have mentioned. you can use the below code
transform.GetChild(0).GetChild(1).gameObject; // this gives you ....break
transform.GetChild(0).GetChild(2).gameObject; // this gives you ... fx
Your answer
Follow this Question
Related Questions
Getting Parent GameObject from Child? 1 Answer
Particles moving past gun. Please help. 1 Answer
Making an object follow another object C# 1 Answer
Question about understanding some tutorial code and transform.parent 1 Answer
I want to make a weapon follow the player after i instatiate the weaponinto the game. 1 Answer