//Use on a large spherecollider with trigger enabled around character to disable particles on enemies when they are out of sight
function Update()
{
}
//trace all collisions and assign them to the col variable
function OnTriggerEnter(col : Collider)
{
//if the tag of col is not "Enemy" then find all objects that do have the "Enemy" tag and turn off the particlerenderer on them
if(col.gameObject.tag !="Enemy")
{
PartEmit = GameObject.FindWithTag("Enemy");
PartEmit.GetComponentsInChildren(ParticleRenderer).enabled = false;
}
//if col does have the "Enemy" tag, then turn on its particlerenderer
if(col.gameObject.tag =="Enemy")
{
col.GetComponentsInChildren(ParticleRenderer).enabled = true;
}
}
Ok, so this is a script that should disable particles when they are too far from the player. This code does run, however it gives me the following error:
MissingFieldException: Field 'UnityEngine.Component[].enabled' not found.
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates)
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.Create (SetOrGet gos)
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.CreateSetter ()
Boo.Lang.Runtime.RuntimeServices.DoCreatePropSetDispatcher (System.Object target, System.Type type, System.String name, System.Object value)
Boo.Lang.Runtime.RuntimeServices.CreatePropSetDispatcher (System.Object target, System.String name, System.Object value)
Boo.Lang.Runtime.RuntimeServices+<SetProperty>c__AnonStorey16.<>m__C ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
ParticleDisabler.OnTriggerEnter (UnityEngine.Collider col) (at Assets/Standard Assets/Scripts/General Scripts/ParticleDisabler.js:16)
So I looked it up and it seems that for some reason gameObject.active = true/false
would work better in some cases, so I tried that and it just gave me a different error:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
ParticleDisabler.OnTriggerEnter (UnityEngine.Collider col) (at Assets/Standard Assets/Scripts/General Scripts/ParticleDisabler.js:16)
Right now I have a felling that it has something to do with where my particles are, as my enemies have the standard assets “Fire1” particle system on them and the spawners for these enemies have the “Enemy” tag.
The spawners are parent objects of the actual enemies, so I thought this should just work, but it seems that somehow it can’t find the particle systems?
Any idea what is going on? Could it perhaps be that GetComponentsInChildren doesn’t work on child object of the parents child objects?
Anyways, Thanks in advance!