Fire torch script with emissionRate obsolete

Hi guys, I downloaded a fire torch asset from the Asset Store and I want to convert the obsolete methods inside the script to the newer ones. This is the old script:

using UnityEngine;
using System.Collections;

public class Torchelight : MonoBehaviour {
  
    public GameObject TorchLight;
    public GameObject MainFlame;
    public GameObject BaseFlame;
    public GameObject Etincelles;
    public GameObject Fumee;
    public float MaxLightIntensity;
    public float IntensityLight;

    void Start () {

        TorchLight.GetComponent<Light>().intensity = IntensityLight;
        MainFlame.GetComponent<ParticleSystem>().emissionRate=IntensityLight*20f;
        BaseFlame.GetComponent<ParticleSystem>().emissionRate=IntensityLight*15f;  
        Etincelles.GetComponent<ParticleSystem>().emissionRate=IntensityLight*7f;
        Fumee.GetComponent<ParticleSystem>().emissionRate=IntensityLight*12f;
    }
  
    void Update () {

        if (IntensityLight < 0)
        {
            IntensityLight = 0;
        }
        if (IntensityLight > MaxLightIntensity)
        {
            IntensityLight = MaxLightIntensity;
        }
        TorchLight.GetComponent<Light>().intensity=IntensityLight/2f+Mathf.Lerp(IntensityLight-0.1f, IntensityLight+0.1f, Mathf.Cos(Time.time*30));
        TorchLight.GetComponent<Light>().color=new Color(Mathf.Min(IntensityLight/1.5f,1f), Mathf.Min(IntensityLight/2f,1f),0f);

        MainFlame.GetComponent<ParticleSystem>().emissionRate=IntensityLight*20f;
        BaseFlame.GetComponent<ParticleSystem>().emissionRate=IntensityLight*15f;
        Etincelles.GetComponent<ParticleSystem>().emissionRate=IntensityLight*7f;
        Fumee.GetComponent<ParticleSystem>().emissionRate=IntensityLight*12f;      
    }
}

emissionRate is obsolte and I tried to fix it without success. Can you give me an help?

Guess you need to change it to emission.rateovertime

I changed it to emission.rateOverTime but I got an error:

The updated code:

using UnityEngine;
using System.Collections;

public class Torchelight : MonoBehaviour {
 
    public GameObject TorchLight;
    public GameObject MainFlame;
    public GameObject BaseFlame;
    public GameObject Etincelles;
    public GameObject Fumee;
    public float MaxLightIntensity;
    public float IntensityLight;

    void Start () {

        TorchLight.GetComponent<Light>().intensity = IntensityLight;

        MainFlame.GetComponent<ParticleSystem>().emission.rateOverTime=IntensityLight*20f;
        BaseFlame.GetComponent<ParticleSystem>().emission.rateOverTime = IntensityLight*15f; 
        Etincelles.GetComponent<ParticleSystem>().emission.rateOverTime = IntensityLight*7f;
        Fumee.GetComponent<ParticleSystem>().emission.rateOverTime = IntensityLight*12f;
    }
 

    void Update () {

        if (IntensityLight < 0)
        {
            IntensityLight = 0;
        }
        if (IntensityLight > MaxLightIntensity)
        {
            IntensityLight = MaxLightIntensity;
        }
        TorchLight.GetComponent<Light>().intensity=IntensityLight/2f+Mathf.Lerp(IntensityLight-0.1f, IntensityLight+0.1f, Mathf.Cos(Time.time*30));
        TorchLight.GetComponent<Light>().color=new Color(Mathf.Min(IntensityLight/1.5f,1f), Mathf.Min(IntensityLight/2f,1f),0f);

        MainFlame.GetComponent<ParticleSystem>().emission.rateOverTime = IntensityLight*20f;
        BaseFlame.GetComponent<ParticleSystem>().emission.rateOverTime = IntensityLight*15f;
        Etincelles.GetComponent<ParticleSystem>().emission.rateOverTime = IntensityLight*7f;
        Fumee.GetComponent<ParticleSystem>().emission.rateOverTime = IntensityLight*12f;     
    }
}

maby emission.rateOverTime.constant

Same error.

EDIT: I fixed it!

using UnityEngine;
using System.Collections;

public class Torchelight : MonoBehaviour {
   
    public GameObject TorchLight;
    public GameObject MainFlame;
    public GameObject BaseFlame;
    public GameObject Etincelles;
    public GameObject Fumee;
    public float MaxLightIntensity;
    public float IntensityLight;
    private ParticleSystem ps;
    private ParticleSystem.EmissionModule em1; // MainFlame emission module
    private ParticleSystem.EmissionModule em2; // BaseFlame emission module
    private ParticleSystem.EmissionModule em3; // Etincelles emission module
    private ParticleSystem.EmissionModule em4; // Fumee emission module

    void Start () {

        TorchLight.GetComponent<Light>().intensity = IntensityLight;

        ps = MainFlame.GetComponent<ParticleSystem>();
        em1 = ps.emission;
        em1.rateOverTime = IntensityLight * 20f;

        ps = BaseFlame.GetComponent<ParticleSystem>();
        em2 = ps.emission;
        em2.rateOverTime = IntensityLight * 15f;

        ps = Etincelles.GetComponent<ParticleSystem>();
        em3 = ps.emission;
        em3.rateOverTime = IntensityLight * 7f;

        ps = Fumee.GetComponent<ParticleSystem>();
        em4 = ps.emission;
        em4.rateOverTime = IntensityLight * 12f;
    }
   
    void Update () {

        if (IntensityLight < 0)
        {
            IntensityLight = 0;
        }
        if (IntensityLight > MaxLightIntensity)
        {
            IntensityLight = MaxLightIntensity;
        }
        TorchLight.GetComponent<Light>().intensity = IntensityLight/2f+Mathf.Lerp(IntensityLight-0.1f, IntensityLight+0.1f, Mathf.Cos(Time.time*30));
        TorchLight.GetComponent<Light>().color = new Color(Mathf.Min(IntensityLight/1.5f,1f), Mathf.Min(IntensityLight/2f,1f),0f);

        ps = MainFlame.GetComponent<ParticleSystem>();
        em1 = ps.emission;
        em1.rateOverTime = IntensityLight * 20f;

        ps = BaseFlame.GetComponent<ParticleSystem>();
        em2 = ps.emission;
        em2.rateOverTime = IntensityLight * 15f;

        ps = Etincelles.GetComponent<ParticleSystem>();
        em3 = ps.emission;
        em3.rateOverTime = IntensityLight * 7f;

        ps = Fumee.GetComponent<ParticleSystem>();
        em4 = ps.emission;
        em4.rateOverTime = IntensityLight * 12f;
    }
}

this one works

ParticleSystem.EmissionModule emission = this.transform.GetComponent<ParticleSystem>().emission;

         emission.rateOverTime = 123;
        Debug.Log(this.transform.GetComponent<ParticleSystem>().emission.rateOverTime.constant);

ok you already fixed it :slight_smile:

Thanks for the reply. There is a way to use only one em variable instead of em1, em2, em3 and em4?

just replace em1,2,3,4 with one EmissionModule called em like you do it with the ps