Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C#

John Moron
John Moron
1,658 Points

UnityEngine.ParticleSystem.EmissionModule; How to Make a video game.

I'm getting this error that the previous ParticleSystem code was obsolete in ParticleSystemDestroyer. Unity said to change it to UnityEngine.ParticleSystem.EmissionModule; So I did that and I got this error Assets/Standard Assets/Utility/ParticleSystemDestroyer.cs(46,66): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement How do I add it as a statment. Please help! using System; using System.Collections; using UnityEngine; using Random = UnityEngine.Random;

namespace UnityStandardAssets.Utility { public class ParticleSystemDestroyer : MonoBehaviour { // allows a particle system to exist for a specified duration, // then shuts off emission, and waits for all particles to expire // before destroying the gameObject

    public float minDuration = 8;
    public float maxDuration = 10;

    private float m_MaxLifetime;
    private bool m_EarlyStop;
    private float ParticleSystem;
    public bool enabled;
    public ParticleSystem.EmissionModule emission;
    private IEnumerator Start()
    {
        var systems = GetComponentsInChildren<ParticleSystem>();

        // find out the maximum lifetime of any particles in this effect
        foreach (var system in systems)
        {
            m_MaxLifetime = Mathf.Max(system.startLifetime, m_MaxLifetime);
        }

        // wait for random duration

        float stopTime = Time.time + Random.Range(minDuration, maxDuration);

        while (Time.time < stopTime || m_EarlyStop)
        {
            yield return null;
        }
        Debug.Log("stopping " + name);

        // turn off emission
        foreach (var system in systems)
        {

        UnityEngine.ParticleSystem.EmissionModule;
            ParticleSystemEmissionType = false;
        }
        BroadcastMessage("Extinguish", SendMessageOptions.DontRequireReceiver);

        // wait for any remaining particles to expire
        yield return new WaitForSeconds(m_MaxLifetime);

        Destroy(gameObject);
    }


    public void Stop()
    {
        // stops the particle system early
        m_EarlyStop = true;
    }
}

}

1 Answer

Seth Kroger
Seth Kroger
56,407 Points

This is one of Unity's own framework source files. You can tell by the fact that it's in the folder Assets\Standard Assets instead of Assets\Scripts. if you edited this file on your own you made a mistake in doing so.

To get back on track here's the version of the file I have for the project on Unity 5.3.4f1:

using System;
using System.Collections;
using UnityEngine;
using Random = UnityEngine.Random;

namespace UnityStandardAssets.Utility
{
    public class ParticleSystemDestroyer : MonoBehaviour
    {
        // allows a particle system to exist for a specified duration,
        // then shuts off emission, and waits for all particles to expire
        // before destroying the gameObject

        public float minDuration = 8;
        public float maxDuration = 10;

        private float m_MaxLifetime;
        private bool m_EarlyStop;


        private IEnumerator Start()
        {
            var systems = GetComponentsInChildren<ParticleSystem>();

            // find out the maximum lifetime of any particles in this effect
            foreach (var system in systems)
            {
                m_MaxLifetime = Mathf.Max(system.startLifetime, m_MaxLifetime);
            }

            // wait for random duration

            float stopTime = Time.time + Random.Range(minDuration, maxDuration);

            while (Time.time < stopTime || m_EarlyStop)
            {
                yield return null;
            }
            Debug.Log("stopping " + name);

            // turn off emission
            foreach (var system in systems)
            {
                system.enableEmission = false;
            }
            BroadcastMessage("Extinguish", SendMessageOptions.DontRequireReceiver);

            // wait for any remaining particles to expire
            yield return new WaitForSeconds(m_MaxLifetime);

            Destroy(gameObject);
        }


        public void Stop()
        {
            // stops the particle system early
            m_EarlyStop = true;
        }
    }
}
John Moron
John Moron
1,658 Points

Omg! Thank you so much for Your help! I will update the script and key you know how it goes!