How to change the start color of a particle inside a prefab?
I have a bubble that floats around the screen, when I click on it to "pop" it, it displays a popping particle system. I want to be able to change the color of that particle system to be the color of the bubble that is being popped.
This is how I instantiate the particle in my bubble class:
public void popBubbleEffect()
{
GameObject newPopEffect = Instantiate(popEffect, gameObject.transform.position, Quaternion.identity) as GameObject;
}
Then inside of my Particle Color class that I attach to the particle system inside my prefab, I have:
public class ParticleColor : MonoBehaviour {
public ParticleSystem prtSystem;
public ParticleSystem.MainModule main;
private Bubble bubble;
// Use this for initialization
void Start () {
bubble = new Bubble();
prtSystem = GetComponent<ParticleSystem>();
main = prtSystem.main;
}
// Update is called once per frame
void Update () {
main = prtSystem.main;
main.startColor = bubble.bubbleColor.color;
}
}
I'm new to Unity so any help would be greatly appreciated. I've browsed multiple pages of google trying to figure this issue out.
Your answer
Follow this Question
Related Questions
Why can I not add my own image to particle material? 1 Answer
Select a random color preset in the particle system through C# 1 Answer
How do I set the statColor of a particle system through script 2 Answers
Changing particle colour (alpha) at runtime 1 Answer
If instantiate prefab is selected how can i change the color? 1 Answer