Particals Not Working

I have a problem where my particles aren’t working when I press space. I’ve been trouble shooting and I don’t know what the problem is. Heres my code:

using UnityEngine;

public class Rocket : MonoBehaviour
{
[SerializeField] float rotationThrust = 100;
[SerializeField] float mainThrust = 100;
[SerializeField] AudioClip mainEngine;

[SerializeField] ParticleSystem mainEngineParticals;
[SerializeField] ParticleSystem RightBooster;
[SerializeField] ParticleSystem LeftBooster;

Rigidbody rb;
AudioSource audioSource;
// Start is called before the first frame update

public void Start()//method
{
    rb = GetComponent<Rigidbody>();//statement
    audioSource = GetComponent<AudioSource>();
}

// Update is called once per frame
void Update()
{
    ProssesThrust();
    ProssesRotation();
}
void ProssesThrust()
{
    if (Input.GetKey(KeyCode.Space)) //can thrust while rotating
    {
        rb.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);
        if (!audioSource.isPlaying)   // so it doesnt layer
        {
            audioSource.PlayOneShot(mainEngine);
        }
        if (!mainEngineParticals.isPlaying)
        {
            mainEngineParticals.Play();
        }
    }
    else
    {
        audioSource.Stop();
        mainEngineParticals.Stop();
    }
}

void ProssesRotation()
{
    if (Input.GetKey(KeyCode.A))//left movement
    {
        ApplyRotation(rotationThrust); //var short for variable
    }
    else if (Input.GetKey(KeyCode.D))//right movement
    {
        ApplyRotation(-rotationThrust);
    }
}
void ApplyRotation(float rotationThisFrame)
{
    rb.freezeRotation = true; //freezing rotation so manually rotate
    transform.Rotate(Vector3.forward * rotationThisFrame * Time.deltaTime);
    rb.freezeRotation = false; //unfreezing rotation so physics system can do the thing
}   

}

1 Like

@Nina

Hi @Bo_Walker,

Check if the ParticleSystem objects from the Hierarchy are assigned to the fields in your Inspector. Do not assign the prefabs from your Assets folder. Only particle systems in the scene/Hierarchy are able to emit particles.

I hope this helped. :slight_smile:


See also:

4 Likes

Thank you! this fixed it

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms