In my game I use rocket engines and I have a sprite for their flames. I need a flame to appear when I press the key that starts an engine and to disappear when I unpress this key. I tried using material for this but Unity sais that color of the material is not a variable and cannot be modified. So how do I do it?
You can make your own materials, and those are okay to change at runtime.
Or you can get a reference to the object that represents the flames and set it inactive/active at runtime.
Or you can get a reference to the component that describes the flames (the Renderer on a 3D object or the Image or something on a 2D object), and set it enabled/disabled at runtime.
Thank you very much that set active advise really helped! But talking about transparency I did try to change it at runtime using my own materials before asking the question and it didn’t work. “Color of the material is not a variable and cannot be modified” is referred to that. So what’s the catch here? Do I need to set some flag “allow to change color” active in the material file?
It tells you what’s wrong in the error message, you need to set the colour of the flame as a variable.
So how do I do that?
I’m not sure.