- Home /
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
Answer by emongev · Mar 21, 2013 at 08:48 PM
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 $$anonymous$$aterial 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
Your answer
![](https://koobas.hobune.stream/wayback/20220613094838im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Vary particle rate using speed 0 Answers
Why is my var not changing? 1 Answer
Enable/Disable of Particles through script 1 Answer
Accessing a variable from js with c# script 1 Answer
Particles emitting after 10 seconds 1 Answer