I Cannot get What is the Problem here. My particle System is not Working

Hi,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Also please check your console in Unity. Maybe there are error messages which indicate what the problem is. Remember you can also look at the lecture code changes via the link in the Resources of each lecture.

Hope this helps :slight_smile:


See also;

Stop replying without Solutions. Stupid

@Pritam95117C

First of i am going to start this with, If you insult our staff members i have NO issue with removing you from our forums
I appreciate the frustration of being stuck but that is no excuse for the insult.

Posting the code as suggested means that we can edit your code and post the corrections for you. In posting your screenshot we cannot do that and it makes our jobs a lot harder.

As it happens this is likely to not be even in the code.
Try checking the particle system transform

I am a teaching assistant as well, but i am also the admin of these forums.

I am Sorry. Forgive me and kindly Send me the correction admin

I dont think this issue actually is within your code.

If you check the particle prefab you made the transform of it should be set to 0 on the X,Y,Z axis so that when it parents to the part of the ship it needs it sit at that point.
Any values in there would offset the position so it could be under the ground when its instantiating.

A good test would be to thrust and check the particle system appears in the heirarchy and whilst thrusting use the pause button with the mouse, then you can check where the particle actually is

I appreciate the apology but its Nina that you should apologise to :slight_smile:

Hope this helps and @Nina is your best person to help you as my focus is primarily the blender courses.

I’m fine. All I need is the code and some information on the project. Then I can help figure out the problem. @Pritam95117C, bear in mind that we do not have access to your computer, so we need your help to be able to help you.

Your screenshots do not show any compiler errors. Are there any error messages in your Unity console? If not, it might be that the wrong particle system is assigned to the exposed fields in the Inspector of your Rocket. To be on the safe side, remove the objects from the particle system field and assign the particle system game objects from the Hierarchy to the field. Not the ones from your Assets folder.

using UnityEngine;
using UnityEngine.SceneManagement;

public class Rocket : MonoBehaviour
{
    [SerializeField] float rcsThrust = 100f;
    [SerializeField] float mainThrust = 100f;

    [SerializeField] AudioClip mainEngine;
    [SerializeField] AudioClip success;
    [SerializeField] AudioClip death;

    [SerializeField] ParticleSystem mainEngineParticles;
    [SerializeField] ParticleSystem successParticles;
    [SerializeField] ParticleSystem deathParticles;


    Rigidbody rigidBody;
    AudioSource audioSource;

    enum State { Alive, Dead, Transcending}
    State state = State.Alive;
    // Use this for initialization
    void Start()
    {
        rigidBody = GetComponent<Rigidbody>();
        audioSource = GetComponent<AudioSource>();

    }

    // Update is called once per frame
    void Update()
    {
        if (state == State.Alive)
        {

            RespondToThrustInput();
            RespondToRotateInput();

        }
        
    }

    private void OnCollisionEnter(Collision collision)
    {
        if(state != State.Alive)
        {
            return;
        }
        switch(collision.gameObject.tag)
        {
            case "Friendly":
                break;
            case "Finish":
                StartSuccessSequence();
                break;
            default:
                StartDeathSequence();
                break;
        }
    }

   
    private void StartSuccessSequence()
    {
        state = State.Transcending;
        audioSource.Stop();
        audioSource.PlayOneShot(success);
        successParticles.Play();
        Invoke("LoadTheNextScene", 1f);
    }
    private void StartDeathSequence()
    {
        state = State.Dead;
        audioSource.Stop();
        audioSource.PlayOneShot(death);
        deathParticles.Play();
        Invoke("LoadTheFirstScene", 1f);
    }


    private void LoadTheNextScene()
    {
        SceneManager.LoadScene(1);
    }
    private void LoadTheFirstScene()
    {
        SceneManager.LoadScene(0);
    }

    private void RespondToThrustInput()
    {
        if (Input.GetKey(KeyCode.Space))// can thrust while rotating
        {
            ApplyThrust();
        }
        else
        {
            audioSource.Stop();
            mainEngineParticles.Stop();
        }
    }

    private void ApplyThrust()
    {
        rigidBody.AddRelativeForce(Vector3.up * mainThrust);
        if (!audioSource.isPlaying)
        {
            audioSource.PlayOneShot(mainEngine);
            
        }
        mainEngineParticles.Play();

    }

    private void RespondToRotateInput()
    {
        rigidBody.freezeRotation=true;
        

        if (Input.GetKey(KeyCode.A))
        {
            float rotationThisFrame = rcsThrust * Time.deltaTime;
            transform.Rotate(-Vector3.forward * rotationThisFrame);
        }
        else if (Input.GetKey(KeyCode.D))
        {
            float rotationThisFrame = rcsThrust * Time.deltaTime;
            transform.Rotate(Vector3.forward * rotationThisFrame);
        }
        rigidBody.freezeRotation = false;
    }

    
}

Now tell me the solution Mam

I’m surprised you’re still getting help after that…

Can you help me please?

Thank you for sharing your code as text. Did you try what I suggested in my previous answer?

Yes but its still not working

Which game object with the Particle System is attached to the field in the Inspector of your Rocket? Click on the field once. A game object should get highlighted in Unity.

Also select the particle system in your Hierarchy and click on the Play button in your scene window. This way, you can test if the particle system itself is working.

Also test this:

    private void ApplyThrust()
    {
        rigidBody.AddRelativeForce(Vector3.up * mainThrust);
        if (!audioSource.isPlaying)
        {
            audioSource.PlayOneShot(mainEngine);
            
        }

        if (!mainEngineParticles.isPlaying)
        {
              mainEngineParticles.Play();
        }     
    }

It might be that the particle system gets restarted whenever the Play() method is called.

1 Like

Thank You it helped

I’m glad your problem is solved. :slight_smile:

What exactly was the solution? The code or the particle system?

1 Like

The Particle System.Thank You

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

Privacy & Terms