Hello
I’m a bit confuse on material and shaders for multiple objects using scripts.
.
Let’s say that I have 2 objects (2D sprites) being the CUBE and the SPHERE. I have to instantiate CUBE and SPHERE to get multiple objects.
All objects and instances use the same shader that have 3 specific properties: _speed, _factor and _delta.
I need that :
-
when I modify _speed, all objects and instances will have this property modified.
-
when I modify _factor, object CUBE and all associated instances will have this property modified.
-
when I modify _delta, only one instance or one object will have this property modified.
.
So many solutions are possible: Instantiate, prefabs, MaterialPropertyBlock, same material… Difficulty is in the fact that Unity will create an instantiated material when modifying one property.
.
Could you please propose a possible way ?
To declare a shader parameter as GLOBAL, you need to remove it from the properties. Then, delare it in the shader as : uniform float _speed. Then in the script; you can access it using: Shader.SetGlobalFloat("_speed", 1.0f); Done...
– Curtice