Particles that follow the Player
I'm making an explosion particle effect, and it's a child of my Player object in the hierarchy. My game is advanced Roll A Ball, and i want the explosion to play when the player falls off a platform. I want the explosion to play, and then the scene to restart (I know how to restart the scene). The particle system should "follow" the player so if he falls off at any point the explosion will play where the player falls. Here's my script:
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement;
public class DeathFall : MonoBehaviour {
void Start()
{
}
void Update()
{
if(gameObject.transform.position.y <= -20 && gameObject.transform.position.y >= -60)
{
//Play the explosion here
}
if(gameObject.transform.position.y <= -60)
{
SceneManager.LoadScene(Application.loadedLevel);
//This restarts the game
}
}
}
Yes, the DeathFall script is attached to the Player. Thank you in advance.
Attach the particle system component to the ball ? Possibly set it to use World space in emission settings and Play the particle effect when your condition becomes true (checkwith a boolean when you do this so you only do it once)
I've tried adding a boolean, but I can't Play it. Here's the script:
using UnityEngine;
using System.Collections;
using UnityEngine.Scene$$anonymous$$anagement;
public class DeathFall : $$anonymous$$onoBehaviour {
public ParticleSystem tpc;
private bool derp = false;
void Start()
{
tpc = gameObject.GetComponent<ParticleSystem> ();
tpc.emissionRate = 0;
}
void Update()
{
if(gameObject.transform.position.y <= -20 && gameObject.transform.position.y >= -60)
{
derp = true;
}
if(gameObject.transform.position.y <= -60)
{
Scene$$anonymous$$anager.LoadScene(Application.loadedLevel);
//This restarts the game
}
if(derp = true)
{
tpc.emissionRate = 1;
//THIS DOESN'T WOR$$anonymous$$!
}
}
}
Your answer
Follow this Question
Related Questions
Script not playing Particle Effect 0 Answers
How would you make a dust trail with a 2d sprite animation? 0 Answers
Particle System Instantiate wrong transform, position on Rig Builder / ragdoll conflict 0 Answers
Particles syncing on the Unity Network 4 Answers
I have a particle system that is playing at the wrong time... 1 Answer