Change color of Particles

Hi,

What I have is an Ellipsoid Particle Emitter, Particle Animator, Particle Renderer, and a World Particle Collider (in that order) attached to a prefab that I have named "ParticlePrefab". The ParticlePrefab is attached to my Player GameObject.

Everytime I press 'h' on the keyboard, I see particles emit, which is what I want. Now I need to be able to change the color of the particles, through a script. Here is what I have so far:

`using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{
// Allow our PlayerClass awareness of the Particle
public GameObject ParticlePrefab;
private GameObject instantiated;

private Vector3 lastPosition;
// Values are set in Unity3D Interface
public float MoveSpeed;
public float RotateSpeed;

// Update is called once per frame
void Update ()
{

Move_Player();

}

void OnTriggerStay(Collider other)
{

if (Input.GetKeyDown("h") && instantiated == null)  
{

    instantiated = (GameObject) Instantiate(ParticlePrefab, transform.position, Quaternion.identity);

    //Particle [] p = p.ColorAnimator = Color.red;

    Particle [] PlayerParticles = particleEmitter.particles;
    for (int i = 0; i < PlayerParticles.Length; i++)
    {
        PlayerParticles*.color = Color.red;*

}
particleEmitter.particles = PlayerParticles;
Color[] MyColor = particleAnimator.colorAnimation;
MyColor[4] = Color.red;
particleAnimator.colorAnimation = MyColor;
}
}
void Move_Player()
{
float MoveForward = Input.GetAxis(“Vertical”) * MoveSpeed * Time.deltaTime;
float MoveRotate = Input.GetAxis(“Horizontal”) * RotateSpeed * Time.deltaTime;
// Move the player
transform.Translate(Vector3.forward * MoveForward);
transform.Rotate(Vector3.up * MoveRotate);
if (Vector3.Distance(lastPosition, transform.position) > 0.01f)
{
lastPosition = transform.position;
if (instantiated != null)
{
instantiated.particleEmitter.emit = false;
Destroy(instantiated, 0.90f);
}
}
}
`


}



If this cannot be done through a script, could someone show me how to use AddComponent so that I can add a particle emitter, of which i will color, the player component and get it to work in the same way?

Here, this will change your colors programatically. I didn't touch much of it so a large part is hard coded like you had it.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class NewBehaviourScript : MonoBehaviour 
{   
// Allow our PlayerClass awareness of the Particle
public ParticleEmitter Particles;

// Values are set in Unity3D Interface
public float MoveSpeed;
public float RotateSpeed;

private ParticleEmitter spawnedParticles;
private ParticleAnimator particleAnimator;

private Vector3 lastPosition;   

// Update is called once per frame
void Update () 
{

    Move_Player();

}

void OnTriggerStay(Collider other)
{

    if (Input.GetKeyDown("h") && spawnedParticles == null)  
    {

        spawnedParticles = Instantiate(Particles, transform.position, Quaternion.identity) as ParticleEmitter;

        particleAnimator = spawnedParticles.GetComponent<ParticleAnimator>();
        Color[] m_Color = particleAnimator.colorAnimation;
        m_Color[4] = Color.red;
        particleAnimator.colorAnimation = m_Color;

    }
}
void Move_Player()
{
    float MoveForward = Input.GetAxis("Vertical")  * MoveSpeed * Time.deltaTime;
    float MoveRotate = Input.GetAxis("Horizontal") * RotateSpeed * Time.deltaTime;

    // Move the player
    transform.Translate(Vector3.forward * MoveForward);
    transform.Rotate(Vector3.up * MoveRotate);

    if (Vector3.Distance(lastPosition, transform.position) > 0.01f)
    {
        lastPosition = transform.position;

        if (spawnedParticles != null)
        {
            spawnedParticles.emit = false;
            Destroy(spawnedParticles.gameObject, 0.90f);
        }
    }
}
}

But unless there is something wrong with the way you have it, using a prefab is likely faster and easier. The old adage "Why fix something that's not broken." seems fitting here.

I'm having the same problem...... I have particle emitters that i want to change the colour of procedurally (as in to flow through from say green to red over time when i prompt it to) how would I go about doing this?