Unity 5 particle-deleting c# Script
NickName:Ivanol mindez Ask DateTime:2015-08-30T22:04:24

Unity 5 particle-deleting c# Script

I was following a unity tutorial started on Unity 4 but I am on Unity 5, and when I try to use the script seen (https://youtu.be/vwUahWrY9Jg?t=1337) and I try to use it, it gives an error:

Assets/Scripts/DestroyFinishedParticle.cs(18,17): error CS0246: The type or namespace name `Destroy' could not be found. Are you missing a using directive or an assembly reference?

this is the code:

using UnityEngine;
using System.Collections;

public class DestroyFinishedParticle : MonoBehaviour {

    private ParticleSystem thisParticleSystem;

    // Use this for initialization
    void Start () {
        thisParticleSystem = GetComponent<ParticleSystem>();
    }

    // Update is called once per frame
    void Update() {
        if (thisParticleSystem.isPlaying)
            return;

        Destroy (GameObject);
    }
}

It can be because C# code for unity changed from 4 to 5? what should I change? The problem seems to be in the Update method.

Copyright Notice:Content Author:「Ivanol mindez」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32297376/unity-5-particle-deleting-c-sharp-script

Answers
Ori Frish 2015-08-30T14:20:40

There are couple of issues with this code.\n\nFirst, you didn't mention to what exactly is it attached too? I assume it attached to the Particle System.\n\nSecondly, use \"gameObject\", not \"GameObject\", since GameObject is the name of the class.\n\nThird, I believe there's a much more efficient way to destroy the gameObject without checking every frame whether the particles system has finished or not, maybe set a small timer? or invoke the function with time?",


More about “Unity 5 particle-deleting c# Script” related questions

Unity 5 particle-deleting c# Script

I was following a unity tutorial started on Unity 4 but I am on Unity 5, and when I try to use the script seen (https://youtu.be/vwUahWrY9Jg?t=1337) and I try to use it, it gives an error: Assets/

Show Detail

Unity for MVC5 in NuGet

I want to use Unity for MVC 5. I found this Link:- http://www.c-sharpcorner.com/UploadFile/dacca2/implement-ioc-using-unity-in-mvc-5/ I don't find Unity Bootstrapper for MVC5 in NuGet. What would...

Show Detail

Unity 5 - Stream Unity Camera to Smartphone

I'm developing currently a drone simulator in Unity 5 and I've got 4 Unity-Cameras in my Scene. I'm working now on a solution to stream the screen of one virtual camera in Unity, to my android smar...

Show Detail

how do i make unity 5.x suport c# 5 or 6?

I want to use the keyword “asyn” in C# script of my visual studio 2015 unity 5.4 project. The compiler shows the following message. Feature asyn function is not available in C# 4. I want to know

Show Detail

Using a Hazelcast Client in Unity 5

I'm currently trying to synchronize an application running in the Unity Engine 5 with a jMonkey Java Engine using Hazelcast. Therefore I wanted to use a C# Client, which Hazelcast provides and inte...

Show Detail

Unity 5 WebGL: Communicating with external javascript from C#

I'm trying to get a Unity 5 WebGL project integrated with SCORM 1.2. This involves the Unity WebGL build communicating with some external javascript. I found this page: https://docs.unity3d.com/...

Show Detail

Using .NET 4.5 code in Unity 5

I am working on a game using Unity3D version 5. The game should use strict business rules already programmed in a C# .NET4.5 engine. Using Xamarin/Mono, we hope to make this usable on windows, andr...

Show Detail

unity project error during export to html5

When i create a blank project on unity 5 and i try to export it to html5, the following message error appears: Failed running "C:\Program Files\Unity\Editor\Data\PlaybackEngines\webglsupport/BuildT...

Show Detail

.rigidbody in Unity 5

When I've tried to use this code in Unity 5 it says that "isKinematic" function is no longer valid in Unity 5 or something like that. Can someone explain why did they make such a change and how ca...

Show Detail

Transparent Shadow Shader Unity5

I use the following shader in unity 4.6.2, but unfortunately it doesn't work in unity5. I have an object in an AR scene (vuforia 4) and I want to show the shadows on a plane which is under the obje...

Show Detail