how to emit particle system attached to object in code?

Hi, i am trying to make a particlesystem(fire) attached to a campfire to be emitted(or change its color at least) when i throw the twig to the campfire, the count is used to count how many twigs are thrown to the campfire,everthing works except the change of color of the particle system fire

public class count : MonoBehaviour {
public int counter;
public Text text;
public Rigidbody fireball;
private ParticleSystem fire;

// Use this for initialization
void Start () {
    counter = 0;
    text.text = "count: " + counter.ToString();
	
}

// Update is called once per frame
void Update () {
	
}
void OnTriggerEnter(Collider other)
{
    if(other.CompareTag("twig"))
    {
       this.GetComponent<ParticleSystem>().startColor = new Color(1, 0, 1, .5f);
        other.gameObject.SetActive(false);
        counter++;
        text.text = "count: " + counter.ToString();
    }
}

}

startColor belongs to the “main module” struct of particle system, so you need to give your particlesystem a var, declare the module of the ps and finally access its properties. You can read the official blog for more details.

In fact, it’s more performance sound to GetComponent/declare your ps and ps module variables on Awake() or OnEnable() instead of Update() on the fly.