How to set Particle Gameobject ON for few seconds?

Hi,

I am trying to ON game object(attached Particle System to empty game object) for few seconds when my character collide with it. But I am not being able to do that.

Here is my code in characterController script:

private GameObject particle;

void Start () 
	{

		particle = GameObject.Find ("Particle");
		particle.SetActive (false);

}
void OnTriggerEnter(Collider other)

	{
		if (other.gameObject.name == "Strawberry") 
		{
			
					Destroy(other.gameObject);
                                        particle.SetActive (true);

}
				
	
	}

This is not working also how to set timing to activate it for few seconds only.

use IEnumerator

void Start(){
StartCoroutine("ParticleShow");
}

IEnumerator ParticleShow(){
particle.SetActive (true);
yield return new WaitForSeconds(5f); //display for 5s
particle.SetActive (false); //I would suggest to destroy it, unless you planning to recycle this object.
}

put this as a script in the particle object. Then from your script:

void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "Strawberry")
{
        Destroy(other.gameObject);
        instantiate(particle, transform.position, Quaternion.Identity);
}
}

Thanks paranoidx…

I have tried this but getting NullReferenceException error.

I have put this code in controller script:

private GameObject particle;

void Start () 
	{
	
		particle = GameObject.Find ("Particle");

}
void OnTriggerEnter(Collider other)

	{
				if (other.gameObject.name == "Strawberry") {
			
						
						Destroy (other.gameObject);
			                        Instantiate(particle, transform.position, Quaternion.identity);
			           
}
		}

Put this script on Particle object:

private GameObject particle;

	
	void Start () {
		particle = GameObject.Find ("Particle");
		StartCoroutine("ParticleShow");
	
	}
	
	
	void Update () {
	
	}
	IEnumerator ParticleShow(){
		
		particle.SetActive (true);
		
		yield return new WaitForSeconds(5f);
		
		particle.SetActive (false); 
		
	}
}