enable/disbale particle system in 5.3.2
Hey all! So I have been after this for an hour now and I've tried using the Unity API but for some reason that doesn't work. Just trying to get my particle system to turn on when an enemy enters my trigger.
using UnityEngine; using System.Collections;
public class Turret2ai : MonoBehaviour { public float rotSpeed; public float spawnWait; public bool doneWaiting; public ParticleSystem fire;
// Use this for initialization
void Start()
{
doneWaiting = true;
//myRigidbody = gameObject.AddComponent<Rigidbody>();
// myRigidbody.constraints = RigidbodyConstraints.FreezePosition;
}
// Update is called once per frame
void Update()
{
}
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Enemy")
{
Quaternion rotation = Quaternion.LookRotation(other.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotSpeed);
fire.emission.enabled = true;
if (doneWaiting)
{
StartCoroutine(Shooting());
other.GetComponent<EnemyHealth>().currentHealth -= 4;
}
}
else
{
fire.emission.enabled = false;
}
}
IEnumerator Shooting()
{
doneWaiting = false;
yield return new WaitForSeconds(spawnWait);
doneWaiting = true;
}
}
(i have also tried doing the var em = fire.emission; em.enabled = true; with no results)
I could be wrong here but I think emission is a relic of the Legacy Particles system.
You Play() a Shuriken system.
Answer by RoofTurkey · Apr 07, 2016 at 01:04 PM
You can use Emit() to directly emit a certain number of particles or Play() to play the particle effect (once if looping is set to false).
Let me know if this works and if not what kind of error you're getting.
AHHH! It was fire.Play(); I kept forgetting to add the (). thanks!
Your answer
Follow this Question
Related Questions
Function using seemingly impossible, unset values 2 Answers
How to rotate RigidBodyFPSController (C#) 1 Answer
how would I add jump to my mecanim free form script 0 Answers
Microphone Input to Spawn object 2 Answers
enemy following issue 0 Answers