This is my code, I am trying to shoot some particles out of the rocket (following rocket boost course) but no particles come out. I’ve assigned them in the inspector and everything. Just doesnt seem to play. I also checked with enginVFX.isPlaying and it returns false…
using System;
using System.Collections;
using UnityEngine;
public class Rocket : MonoBehaviour {
[SerializeField] float rcsThrust = 100f;
[SerializeField] float mainThrust = 100f;
[SerializeField] AudioClip mainEngine;
[SerializeField] AudioClip success;
[SerializeField] AudioClip death;
[SerializeField] ParticleSystem deathVFX;
[SerializeField] ParticleSystem engineVFX;
[SerializeField] ParticleSystem successVFX;
Rigidbody rigidBody;
AudioSource audioSource;
LevelLoader levelLoader;
enum State { Alive, Dying, Transcending }
State state = State.Alive;
bool collisionToggleEnabled = true;
// 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();
}
if (Debug.isDebugBuild){
RespondToDevInput();
}
}
private void RespondToDevInput()
{
if (Input.GetKeyDown(KeyCode.C)){
collisionToggleEnabled = false;
print("Collider disabled");
}
}
void OnCollisionEnter(Collision collision)
{
if (state != State.Alive || !collisionToggleEnabled) { return; }
switch (collision.gameObject.tag)
{
case "Friendly":
// do nothing
break;
case "Finish":
StartSuccessSequence();
break;
default:
StartDeathSequence();
break;
}
}
private void StartSuccessSequence()
{
state = State.Transcending;
audioSource.Stop();
AudioSource.PlayClipAtPoint(success, transform.position);
ParticleSystem successVFX_ = Instantiate(successVFX, transform.position, Quaternion.identity);
successVFX_.Play();
FindObjectOfType<LevelLoader>().LoadNextLevel();
Destroy(gameObject);
}
private void StartDeathSequence()
{
state = State.Dying;
audioSource.Stop();
AudioSource.PlayClipAtPoint(death, transform.position);
ParticleSystem deathVFX_ = Instantiate(deathVFX, transform.position, Quaternion.identity);
deathVFX_.Play();
FindObjectOfType<LevelLoader>().ReloadLevel();
Destroy(gameObject);
}
private void RespondToThrustInput()
{
if (Input.GetKey(KeyCode.Space))
{
ApplyThrust();
}
else
{
audioSource.Stop();
engineVFX.Stop();
}
}
private void ApplyThrust()
{
engineVFX.Play();
rigidBody.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);
if (!audioSource.isPlaying) // so it doesn't layer
{
audioSource.PlayOneShot(mainEngine);
}
}
private void RespondToRotateInput()
{
rigidBody.freezeRotation = true; // take manual control of rotation
float rotationThisFrame = rcsThrust * Time.deltaTime;
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward * rotationThisFrame);
}
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(-Vector3.forward * rotationThisFrame);
}
rigidBody.freezeRotation = false; // resume physics control of rotation
}
}