I have a particle system created, and in a certain point in my game I would like to increase the max particles.
As a result, I created a game object and attached a box 2d collider to it that fires when it comes in contact with the player. In that script, I have created a public GameObject leafParticleSystem, and dragged the particle system into it.
However, in my code, I am unable to do anything like
leafParticleSystem.maxParticles=500;
or
leafParticleSystem.emission.rate=5.0f
My code is also saying
"MissingComponentException: There is no 'ParticleSystem' attached to the "Herld" game object, but a script is trying to access it.
You probably need to add a ParticleSystem to the game object "Herld". Or your script needs to check if the component is attached before using it.untime/Export/Coroutines.cs:17)"
However, this "Herld" GameObject is not the particle system (nor do I want to add one to it) It however, does have the script attached which I am dragging the particle system (leaf particle system) to. I am just trying to modify the leaf particle system from my code in the "Herld" object.
Would appreciate if I could get any assistance
Script Attached
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class WindEffect : MonoBehaviour {
// Rigidbody2D _rigidbody;
// Use this for initialization
//Storm Warning
public GameObject AOE;
public GameObject UIStormInterface;
public GameObject UIWindZone;
public GameObject LeafStormParticleSystem;
public float ActivateFor=5.0f;
public float stormLength=5.0f;
void Start () {
}
// Update is called once per frame
void Update () {
}
void Awake () {
// _rigidbody = GetComponent<Rigidbody2D> ();
}
void OnTriggerEnter2D(Collider2D col)
{
// Debug.Log("Object touched trigger");
// Debug.Log (col.transform.name);
if (col.gameObject.name == "Player") {
Debug.Log ("Collided with Storm Herald");
StartCoroutine (TemporarilyActivateStormWarning (ActivateFor));
}
}
private IEnumerator TemporarilyActivateStormWarning(float ActivateFor) {
//Show Storm Warning
this.gameObject.GetComponent<BoxCollider2D>().enabled=(false);
UIStormInterface.GetComponent<Text>().text="A Violent Storm is Approaching";
UIStormInterface.SetActive(true);
UIWindZone.SetActive (true);
//Wait for 5 seconds then activate storm for 5 seconds
yield return new WaitForSeconds(ActivateFor);
UIStormInterface.SetActive(false);
AOE.SetActive (true);
// ParticleSystem LeafStormParticleSystem = GetComponent<ParticleSystem>();
// LeafStormParticleSystem.emission.rate = 5.0f;
LeafStormParticleSystem.maxParticles = 500;
yield return new WaitForSeconds(stormLength);
//Turn off Storm
AOE.SetActive (false);
//Tell user storm is stopped for 2 seconds.
UIStormInterface.GetComponent<Text>().text="Storm has Passed";
UIStormInterface.SetActive(true);
yield return new WaitForSeconds(3);
UIStormInterface.SetActive(false);
UIWindZone.SetActive (false);
}
void OnTriggerStay2D(Collider2D col)
{
if (col.gameObject.name == "WindObject") {
Debug.Log ("Collided");
// Debug.Log (col.transform.name);
// Wind();
//StartCoroutine(WindStart());
}
}
/*
IEnumerator WindStart(){
Debug.LogError ("Slow Time.");
//SlowTheTime();
// yield return new WaitForSeconds(3.5f);
// Debug.LogError ("Slow Time.");
// Wind ();
}*/
void OnCollisionEnter2D(Collision2D col)
{
// Debug.Log (col.transform.name);
}
void OnTriggerStay(Collider col)
{
Debug.Log("Object is in trigger");
}
void OnTriggerExit(Collider other)
{
Debug.Log("Object left the trigger");
}
/*
void Wind(){
_rigidbody = GetComponent<Rigidbody2D> ();
Debug.Log ("test got here");
Debug.Log (this.gameObject.name);
this._rigidbody.AddForce (-Vector2.left * 100 );
}*/
}
leafParticleSystema reference to it? - SerliteleafParticleSystemis a public GameObject variable, onto which you dragged the GameObject "Herld" (which has theWindEffectcomponent attached)? And the particle system you want to access is stored in the public variableLeafStormParticleSystemof theWindEffectscript? - SerliteleafParticleSystemthe GameObject with the particle system on it, or is itLeafStormParticleSystem? I'm having trouble visualizing the relationship based on your last comment. - Serlite