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
}
}