Following Along with the Game Dev Course on Udemy and unable to get my particles to trigger working on the Project boost portion of the course.
I don’t think it’s the code(although I could be wrong, im new)
Anyone able to help?
Following Along with the Game Dev Course on Udemy and unable to get my particles to trigger working on the Project boost portion of the course.
I don’t think it’s the code(although I could be wrong, im new)
Anyone able to help?
Hi,
Could you share your code, please? And in which course and section are you?
I am in Section 3: Introducing Particle Effects.
The Cod is as follows. Very new to coding and any help would greatly appreciated.
using UnityEngine;
using UnityEngine.SceneManagement;
public class Rocket : MonoBehaviour
{
[SerializeField] float rcsThrust = 100f;
[SerializeField] float mainThrust = 100f;
[SerializeField] AudioClip mainEngine;
[SerializeField] AudioClip death;
[SerializeField] AudioClip success;
[SerializeField] ParticleSystem mainEngineParticles;
[SerializeField] ParticleSystem successParticles;
[SerializeField] ParticleSystem deathParticles;
Rigidbody rigidBody;
AudioSource audioSource;
enum State { Alive, Dying, Transcending}
State state = State.Alive;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
if (state == State.Alive)
{
RespondToThrustinput();
RespondToRoatateinput();
}
}
void OnCollisionEnter(Collision collision)
{
if (state != State.Alive) { return; }
switch (collision.gameObject.tag)
{
case "Friendly":
print("Okay");
break;
case "Finish":
StartSuccessSequence();
break;
default:
StartDeathSequence();
break;
}
}
private void StartSuccessSequence()
{
state = State.Transcending;
audioSource.Stop();
audioSource.PlayOneShot(success);
successParticles.Play();
if (!successParticles.isPlaying)
{
successParticles.Play();
}
Invoke("LoadNextLevel", 1f);
}
private void StartDeathSequence()
{
state = State.Dying;
audioSource.Stop();
audioSource.PlayOneShot(death);
deathParticles.Play();
Invoke("LoadFirstLevel", 1f);
}
private void LoadFirstLevel()
{
SceneManager.LoadScene(0);
}
private void LoadNextLevel()
{
SceneManager.LoadScene(1);
}
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);
}
if (!mainEngineParticles.isPlaying)
{
mainEngineParticles.Play();
}
}
void RespondToRoatateinput()
{
float rotationThisFrame = rcsThrust * Time.deltaTime;
rigidBody.freezeRotation = true;// take manual controll of rotation
if (Input.GetKey(KeyCode.A))
{
print("Rotating Left");
transform.Rotate(Vector3.forward * rotationThisFrame);
}
else if (Input.GetKey(KeyCode.D))
{
print("Rotating Right");
transform.Rotate(Vector3.back * rotationThisFrame);
}
rigidBody.freezeRotation = false;// to resume physics controll of rotation
}
}
Did you check whether the particle system from your Hierarchy is attached to the exposed field in the Inspector? If it is the prefab from your Assets folder, you will not see anything.
See also:
Not entirely sure what you mean? How would I go about do so?
I am VERY new to coding and even less experience with unity
First of all, click on your Rocket game object in your Hierarchy. Then take a look at your Inspector. There should be a field in your Rocket component where you can attach the Particle System. Click on that field and press the del key on your keyboard.
Then drag and drop the game object from your Hierarchy with the Particle System attached into the field.
Test your game again.
That Worked!!!
Thank you so much for taking the time to help with this issue!
You’re welcome.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.