Particle system rate by speed of vehicle

Hello,
First thanks for your time reading.

what I want is;
Smoke out of the engine of the car via partycle system. When moving faster I want more smoke ( higher emission rate)

I tried:

using UnityEngine;
using System.Collections;

public class CarSound : MonoBehaviour {

public float topSpeed = 100; // km per hour
private float currentSpeed = 0;
public ParticleSystem.EmissionModule emission;

       void Update () {
		currentSpeed = transform.GetComponent <Rigidbody> ().velocity.magnitude * 3.6f;

        emission = currentSpeed / topSpeed;

		transform.GetComponent <ParticleSystem> ().emission = emission;
	}
}

I cant test it because I get few errors:

Particle.emission cannot be assigned to ‘it is read only’.

I cant fix it my self. I am still a beginner and I don’t know that much!

Anyone with a solution ?

Kind regards,
Ranec

Just grab a reference to emission object and change emission value in that reference. Like this:

var emissionController = gameObject.GetComponent<ParticleSystem>().emission;
emissionController .rateOverTime = emission;

Update:

Misread your script a bit. Here’s the solution that works:

public class CarSound : MonoBehaviour {

    public float topSpeed = 100; // km per hour
    private float currentSpeed = 0;
    public ParticleSystem particleSystem;

    void Update()
    {
        currentSpeed = transform.GetComponent<Rigidbody>().velocity.magnitude * 3.6f;
        float emissionAmount = currentSpeed / topSpeed;

        var emissionController = particleSystem.emission;
        emissionController.rateOverTime = emissionAmount;
    }
}