So:
I am using unity 2021.1.16f.
I am currently buidling a scene with some particesystems and stumbled across the problem not beeing able to easily detect a particles death or birth, to play sound on it. Now I have tried using a technique of counting how many particles there are and if its not there anymore is makes a sound, however that worked almost, since the sounds sometimes just did not play and sometimes cut off. Anyways, I found an article (https://everfounders.com/unity-particle-system/) by a Person giving a full tutorial about how to achieve that with tricks and techniques I yet have learned. The problem is just, that the code is outdated, for example I have to write [System.Serializable] instead of only [Serializable]. And that is exactly where my real problem begins:
I am trying to reproduce this code:
[Serializable]
public class ParticlesInfo
{
public ParticleSystem system;
public AudioClip sound;
public bool callEventsOnce;
public ParticlesEvent onBirth;
public ParticlesEvent onDeath;
[HideInInspector]
public float[] m_times;
[HideInInspector]
public ParticleSystem.Particle[] m_particles;
[HideInInspector]
public bool birthInvoked;
[HideInInspector]
public bool deathInvoked;
}
[Serializable]
public class ParticlesEvent : UnityEvent<ParticlesInfo>
{
}
I changed Serializable to System.Serializable and UnityEvent to UnityEvent :
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class PacrticleEvents : MonoBehaviour
{
}
[System.Serializable]
public class ParticlesInfo
{
public ParticleSystem system;
public AudioClip sound;
public bool callEventsOnce;
public ParticlesEvent onBirth;
public ParticlesEvent onDeath;
//[HideInInspector]
public float[] m_times;
//[HideInInspector]
public ParticleSystem.Particle[] m_particles;
//[HideInInspector]
public bool birthInvoked;
//[HideInInspector]
public bool deathInvoked;
}
[System.Serializable]
public class ParticlesEvent : UnityEvent <ParticlesInfo>
{
public ParticlesInfo[] Particles;
}
What, so it says in the article, should show is this:
However [System.Serializable] not work. I have no ability at all, to see or change variables or other stuff in the Inspector. I don’t know what I have done wrong. I did try to change my base class of ParticlesInfo
to Monobehavior, but that didn’t do anything at all.
So I am really Stuck and I wanna finish this until New Year, so I really hope someone can helpme with this.
Also already Thanks to everyone who will answer to this post, because that is definitly something.