Home>
Thing I want to do

We are creating a fireworks display where you can specify the color.

Currently, the color is specified after instantiation, so I want to specify the color in the prefab before instantiation.

Prefabricated fireworks particles
Parent: Particle launch
Child: fire explosion

Be in trouble

I made it possible to change the color of fire by keyboard input, but it will be possible to change it at any time during the launch (while the fireworks are rising).
So by changing the color of the prefab with the keyboard, I want the instantiated fireworks color to inherit the color of the prefab.

Press the A button to set the fire start color to red.
Press the W button to set the fire start color to green.

The script below is attached to the prefab.

C #
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class color: MonoBehaviour
{
    public ParticleSystem firework1_kid;
    public Color32 newColor = new Color32 ();
    void Start ()
 {{
    }
    // Update is called once per frame
void Update ()
    {
        if (Input.GetKeyDown (KeyCode.A))
        {
            Red ();
            //firework1_kid.startColor = newColor;
        }
        else if (Input.GetKeyDown (KeyCode.W))
        {
            Green ();
            //firework1_kid.startColor = newColor;
        }
    }
    public void Red ()
    {
        newColor = new Color32 (255, 0, 0, 255);
        firework1_kid.startColor = newColor;
    }
    public void Green ()
    {
        newColor = new Color32 (0, 255, 0, 255);
        firework1_kid.startColor = newColor;
    }
}
What I tried

When I checked the start color of the prefab fire during execution, the color did not change.
So I found out that the color script was running after the instance was created.

The system is set up so that an instance is created when the space key is pressed in another script.
I'm currently looking for ways to configure prefabs from instance creation, but I can't come up with an idea.