- Home /
The question is answered, right answer was accepted
How do I use a particle system?
I want to call upon the particle system when my player dies as an animation, but I don't know how to do this. It is giving me this error "The type or namespace name 'Play' does not exist in the namespace 'System' (are you missing an assembly reference?)." I want to be able to have the animation/particle system play when the player dies, how do I make that happen?
This is my code so far:
using System.Collections;
using System.Collections.Generic; using UnityEngine;
public class DestroyContact : MonoBehaviour {
PlayerController playerMovement;
ParticleSystem animate;
public bool dead;
void Awake()
{
playerMovement = GetComponent <PlayerController> ();
animate = GetComponent <ParticleSystem> ();
}
void Update(){
}
void OnTriggerEnter (Collider other)
{
if(other.gameObject.tag == "Floor")
{
return;
}
if(other.gameObject.tag == "Collider");
Destroy(gameObject);
PlayerDead ();
}
void PlayerDead()
{
dead = true;
playerMovement.enabled = false;
System.Play(animate); //this is where it is giving me the error
}
}
Answer by OneCept-Games · Jan 03, 2018 at 09:06 PM
First of all, ParticleSystem is not an Animation, so your naming might confuse you later.
Next, try to start the ParticleSystem by:
animate.Play(true);
Answer by S_jay1 · Jan 04, 2018 at 05:22 PM
I changed it to particleSystemPlayer.Play(true); after changing the name from animate to particleSystemPlayer. The error is now gone but how would I make the particle system to play at the position in which the player died at?
You would position the particleSystemPlayer at the same position before starting it:
In your case: particleSystemPlayer.transform.position = player.transform.position;
I set the position of the system to the position of the player and then set it to play and it works perfectly. Thank you so much!