Using the name of one variable to call another

I am currently looking for a way to choose a particle effect based on the object material. For example:

var material = wood;
//material could be one of many other values

<material>Particles.Emit();

Essentially if the material was wood it would emit woodParticles (assigned earlier in the code) if it was metal it would emit metalParticles.

Thanks, Langy

1 Answer

1

As a quick fix maybe you could try using the materials name “wood” or “metal” (as a result of converting it to string or whatever) and using that to attach the -name- + “Particles” prefab, that way it would choose which particles to attach depending on the materials name

This is what I was after yeah, is the above the correct syntax for it? i.e. if Material was "wood" and I wrote: -material- + "Particles".Emit(); it would emit the wood particles? Thanks

–

Id personally do several prefabs each with each type of particle, then add them to an array of GameObjects then Instantiate the prefab i found by name (not the best way, but thats what i can think of right now, sorry i cant delve much deeper on the solution, im currently at work :P

–