I am trying to create particles emission for my objects which are actually pawns in a chess game. I changed particles material using Inspector for particle system and it works fine, however, when I try to change it with a script, nothing happens (particles stay pink for the black pawn).
I am not sure what is wrong with the script, whether it's a change of material problem or maybe I need to set the path for material. I would be glad if someone suggested a solution!
Here is the script:
public class BlackPawnParticleSystem : MonoBehaviour
{
private Material m_Material;
private ParticleSystemRenderer psr;
private void Start()
{
var ps = GetComponent<ParticleSystem>();
m_Material = GetComponent<Renderer>).material;
psr = GetComponent<ParticleSystemRenderer>);
psr.material = Resources.GetBuiltinResource<Material>("BlackBishop.mat");
}
This is how it looks like:
EDIT:
Changes in code:
public class BlackPawnParticleSystem : MonoBehaviour
{
private Material m_Material;
private ParticleSystemRenderer psr;
private void Start()
{
var ps = GetComponent<ParticleSystem>();
m_Material = GetComponent<Renderer>().material;
psr = GetComponent<ParticleSystemRenderer>();
psr.material = Resources.Load<Material>("BlackBishop");
}
Inspector for the material:
Script attached to the object:
ParticleSystem
. The way Unity exposes theParticleSystem
objects is quite strange, I would look into it. – Douglas DwyerGetBuiltinResource
returns null, which would result in pink particles. – Douglas Dwyer