I have to make a fireworks particle play when the balloon touches a dollar sign,
I have been successful to play the particle effect when it touches the sign, but the effect does not take place at the place of collision. It happens randomly at any point of the game.
How do I make the particle effect follow the balloon ( it is my player).
Here is my script,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControllerX : MonoBehaviour
{
public bool gameOver ;
private float floatForce = 10;
private float gravityModifier = 1.5f;
private Rigidbody playerRb;
public ParticleSystem explosionParticle;
public ParticleSystem fireworksParticle;
private AudioSource playerAudio;
public AudioClip moneySound;
public AudioClip explodeSound;
// Start is called before the first frame update
void Start()
{
Physics.gravity *= gravityModifier;
playerAudio = GetComponent<AudioSource>();
// Getting the Rigid Body component of the balloon
playerRb = GetComponent<Rigidbody>();
// Apply a small upward force at the start of the game
playerRb.AddForce(Vector3.up * floatForce/3, ForceMode.Impulse);
}
// Update is called once per frame
void Update()
{
// When space is pressed and player is low enough, float up
if (Input.GetKeyDown(KeyCode.Space) && gameOver == false)
{
playerRb.AddForce(Vector3.up * floatForce, ForceMode.Impulse);
}
}
private void OnCollisionEnter(Collision other)
{
// if player collides with bomb, explode and set gameOver to true
if (other.gameObject.CompareTag("Bomb"))
{
explosionParticle.Play();
playerAudio.PlayOneShot(explodeSound, 1.0f);
gameOver = true;
Debug.Log("Game Over!");
Destroy(other.gameObject);
}
// if player collides with money, fireworks
else if (other.gameObject.CompareTag("Money"))
{
playerAudio.PlayOneShot(moneySound, 1.0f);
Destroy(other.gameObject);
fireworksParticle.Play();
}
}
}
I am a noob so please explain in plain english.,