I did the code just as he said, and I even copied his script down and its not playing. I imported the particles and added them to my rocket ship, and added them to my variables.
Hi,
In the rocket component, did you reference the ParticleSystem from the child game objects of the rocket? The ParticleSystem must be in the scene (= in the Hierarchy). Otherwise, you will not see any particles.
Are there any error messages in your console when you expect to see the particles? Have you already tried to add Debug.Logs to your code to see what is going on during runtime?
What do you mean when you ask if I referenced the ParticleSystem from the child game objects of the rocket? I made both particles children of the my rocket prefab and attached them to their corresponding variables. It appears that the script is just going over the code that starts the particles and ignores it.
Here are some screenshots:
As you can see, the Particle Systems are children of my rocket.
Here is my scripts for the collision handler:
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionHandler : MonoBehaviour
{
[SerializeField] float delayInSeconds = 2f;
[SerializeField] float delayInSecondsForWin = 5f;
[SerializeField] AudioClip winSound;
[SerializeField] AudioClip crashSound;
[SerializeField] ParticleSystem succesParticles;
[SerializeField] ParticleSystem crashParticles;
AudioSource audioSource;
bool isTransitioning = false;
void Start()
{
audioSource = GetComponent<AudioSource>();
}
void OnCollisionEnter(Collision other)
{
if (isTransitioning)
{
return;
}
switch (other.gameObject.tag)
{
case "Friendly":
break;
case "Finish":
Win();
break;
case "Obstacle":
Crash();
break;
default:
Crash();
break;
}
}
void Win()
{
isTransitioning = true;
audioSource.Stop();
succesParticles.Play();
audioSource.PlayOneShot(winSound);
GetComponent<Movement>().enabled = false;
Invoke("LoadNextLevel", delayInSecondsForWin);
}
void Crash()
{
isTransitioning = true;
audioSource.Stop();
crashParticles.Play();
audioSource.PlayOneShot(crashSound);
GetComponent<Movement>().enabled = false;
Invoke("Restart", delayInSeconds);
}
void LoadNextLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
int nextSceneIndex = currentSceneIndex + 1;
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
{
nextSceneIndex = 0;
}
SceneManager.LoadScene(nextSceneIndex);
}
void Restart()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
}
That’s exactly what I meant.
In your code, you have Invoke("Restart", delayInSeconds);
. Comment the lines with Invoke out: // Invoke("Restart", delayInSeconds);
. Then test your game again. Do the particles appear?
If not, there is a problem with the particle system. If they do appear, delayInSeconds
is too low. The particle system needs at least a few seconds to emit particles.
You could also try to enable “Prewarm” in the particle system. This often fixes certain issues with the emission.
The particles still do not appear. I commented the invoke lines out and it still didn’t work. I also tried setting the delayInSeconds to 5, and it didn’t work. I also tried enabling “Prewarm” and the particles still did not appear. The particles are working though, because when I select them they start emitting. It is only during runtime that when I hit an obstacle or beat the level the particles do not appear.
Im sorry, I accidentaly clicked the “solved” button. I will create a new topic: Particles do not trigger at all! V2
You were right! I needed to reference the particles in my scene, not just my prefabs!
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.