I am trying to make a 2D game in Unity. I want to have an object have particles when they move or when being pushed. I am still a beginner at this, all help would be much appreciated.
CodePudding user response:
Create a Particle System. Under "Emission", enter the desired value at "Rate over Distance". This will create particles, whenever the object moves. No particles emitted when the object remains still. Per default, there is a value in "Rate over time" which will emit continuously.
https://docs.unity3d.com/Manual/PartSysEmissionModule.html
CodePudding user response:
Create a particle system attach it as a child and add a script to the object from which you want particles to come out. If your object has a rigid body use it’s velocity.magnitude option to check the magnitude of its velocity and activate the particle system when needed.
public GameObject particles;
public RigidBody2D rb;
private void Start()
{
rb = gameObject.GetComponent<RigidBody2D>();
}
private void Update()
{
if(rb.velocity.magnitude > 0)
{
particles.SetActive(true);
particles.GetComponent<ParticleSystem>().Play();
}
else
{
particles.SetActive(false);
}
}
Also don’t forget to drag the particle system game object in the inspector into the particles property.