Hi there,
I am about to throw my PC out of the window xD. This issue is driving me nuts. So I have screened through this forum and tried every suggestion here. Nothing seemed to have worked for me. However, the trigger “Particle.play” is translated over to the log of Unity meaning that when pressing space it should display that visual.
if (audioSource.isPlaying == false) //no sound overlay
{
audioSource.PlayOneShot(mainEngine);
mainEngineParticles.Play();
print("Particle running");
I see in the log file that the condition is triggered to play the particle effect. However, It won’t show it in game. I have tried every single tweak on the inspection slider too (as suggested here in some of the posts). The only way I get this to work is by pressing “Play on awake”. From there I also tried to “disable” that effect in the code when pressing space. Doesnt work either. So here I am trying to figure out this problem for a good 2 hours and about to move the whole rocket thing into the trash can xD. But yeah will need to experiment around. Someone still having issues with the particles even with all these suggestions here?
There is clearly something interrupting the visual display of
engineParticles.Play();
EDIT:
I also cant make the death particles running on impact. I will submit here the whole code, maybe you can spot something.
public class FlyingInput : MonoBehaviour
{
Rigidbody rigidBody;
AudioSource audioSource;
[SerializeField] float rcsThrust = 100F; // Definition of the rotation speed of the rocket
[SerializeField] float mainThrust = 100F;
[SerializeField] AudioClip mainEngine;
[SerializeField] AudioClip GameOver;
[SerializeField] AudioClip IdleThrust;
[SerializeField] AudioClip Success;
[SerializeField] ParticleSystem mainEngineParticles;
[SerializeField] ParticleSystem successParticles;
[SerializeField] ParticleSystem deathParticles;
int sceneNumber;
enum State { Alive, Dying, Transcending, Idling}
State state = State.Alive;
public void Start()
{
rigidBody = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
sceneNumber = SceneManager.GetActiveScene().buildIndex;
}
int currentScene = SceneManager.GetActiveScene().buildIndex;
public void OnCollisionEnter(Collision collision)
{
if (state != State.Alive) { return; }
switch (collision.gameObject.tag)
{
case "Friendly":
print("Friend");
break;
case "Final":
state = State.Transcending;
if (sceneNumber == 1)
{
Invoke("LoadCurrentScene", 1f);
}
else if (sceneNumber == 0)
{
Invoke("LoadNextScene", 1f);
}
break;
default:
state = State.Dying;
if (sceneNumber == 0)
{
deathParticles.Play();
audioSource.Stop();
audioSource.PlayOneShot(GameOver);
Invoke("LoadCurrentScene", 4f);
}
else if (sceneNumber == 1) {
deathParticles.Play();
audioSource.Stop();
audioSource.PlayOneShot(GameOver);
{ Invoke("LoadNextScene", 4f); }
}
break;
}
}
public void LoadNextScene()
{
SceneManager.LoadScene(1);
}
public void LoadCurrentScene()
{
SceneManager.LoadScene(0);
}
public void Update() {
if (state == State.Alive)
{
ProcessInput();
}
void ProcessInput()
{
Thrust();
MovementAxis();
}
void MovementAxis()
{
if (Input.GetKey(KeyCode.W))
{
rigidBody.AddRelativeForce(Vector3.forward);
}
if (Input.GetKey(KeyCode.S))
{
rigidBody.AddRelativeForce(Vector3.down);
}
else Rotate();
}
}
public void Rotate()
{
rigidBody.freezeRotation = true;
float rotationSpeed = rcsThrust * Time.deltaTime;
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward * rotationSpeed);
}
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(Vector3.back * rotationSpeed);
}
rigidBody.freezeRotation = false;
}
public void Thrust()
{
float Booster = mainThrust * Time.deltaTime;
if (Input.GetKey(KeyCode.Space))
ApplyThrust(Booster);
else
{
audioSource.Stop();
mainEngineParticles.Stop();
}
}
public void ApplyThrust(float Booster)
{
rigidBody.AddRelativeForce(Vector3.up * Booster);
if (audioSource.isPlaying == false) //no sound overlay
{
audioSource.PlayOneShot(mainEngine);
mainEngineParticles.Play();
print("Particle running");
}
}
}