Errors in code(SOLVED) and poor method(SOLVED)

hi and thanks in advance

I don’t really know what this error means but here it is this is a trigger script that throws up this error

heres the code (which)

var flames : GameObject = GameObject.Find("Fireball"); 

	


function OnControllerColliderHit(hit : ControllerColliderHit) 
{    
	var flameEmitter : ParticleEmitter = flames.GetComponent(ParticleEmitter);
   if (hit.gameObject.tag == "Firepit") 
   { 		
		
		flameEmitter.enabled = true;
		Debug.Log ("I'm on FIRE"); 
		yield WaitForSeconds (2);
		Debug.Log ("Oh Wait"); 
		flameEmitter.enabled = false;
		Debug.Log ("No i'm fine"); 
   } 
}

this method also leaves a small error in that it leaves any visible particles hovering in place in the scene here

flameEmitter.enabled = false;

until the component is enabled again

another method i tried was

		flameEmitter.emit = true;
		Debug.Log ("I'm on FIRE"); 
		yield WaitForSeconds (2);
		Debug.Log ("Oh Wait"); 
		flameEmitter.emit = false;
		Debug.Log ("No i'm fine");

but this removes the game object

var flames : GameObject = GameObject.Find("Fireball");

being the particle emiter object

I am begining to believe i may need to instantiate the object and destroy it when i’m done but i don’t really want to use that method.

i would much prefer the .emit = true; method as it makes more sense but declaring .emit = false; causes it to remove the object so it seems like a F@*XD if i do, F@*XD if i don’t situation. so any help or advice would be much appreciated thanks again.

Exactly which line was the exception thrown on?

As for the particles, I saw this in an example script:

var particles : Component[] = GetComponentsInChildren(ParticleEmitter);
for (var p : ParticleEmitter in particles)
{
	p.emit = false; // or true
}

Hope this helps.

it doesn’t say which line it just gives this error i tried searching the error and i got these 3 result which helps me none

http://forum.unity3d.com//files/editor_134.txt
http://www.unity3d.ru/distribution/viewtopic.php?f=5&t=1500

the entire error reads:

i’m also having a little trouble implementing this example you gave me lol i’m a dumbass.

i’ve tried the unity scripting refs but they seem very vague to me and any time i have used it there seems to be minor errors that drive me nuts for days eg: Animation.Play(scripting ref) when it realy is animation.Play.

See if you can double click the error on the console. Sometimes it will take you to the line of code that’s causing issues.

I’ll try to see if I can rewrite some of the code you provided shortly to fit the example. Getting food together at the moment. lol

it seems to be the line

var flames : GameObject = GameObject.Find("Fireball");

i tried moving it to inside the function and the error went away woo hoo but all the method bugs above continue(removing object after with .emit =false; / visible particles with .enabled =false;)

Try this code out and let me know if it works. If it does, I can explain the reasonings behind it.

var emittedFlames : Component[];

function Start() {
	emittedFlames = GameObject.Find("Fireball").GetComponents(ParticleEmitter); 
}

function OnControllerColliderHit(hit : ControllerColliderHit) 
{    
	if (hit.gameObject.tag == "Firepit") 
	{        	
		for (var p : ParticleEmitter in emittedFlames)
		{
			p.emit = true;
		}
		Debug.Log ("I'm on FIRE"); 
		yield WaitForSeconds (2); 
		Debug.Log ("Oh Wait"); 
		for (var p : ParticleEmitter in emittedFlames)
		{
			p.emit = false;
		}
		Debug.Log ("No i'm fine"); 
	} 
}

this works as perfectly as

function OnControllerColliderHit(hit : ControllerColliderHit) 
{    
var flames : GameObject = GameObject.Find("Fireball"); 
	var flameEmitter : ParticleEmitter = flames.GetComponent(ParticleEmitter);
	
   if (hit.gameObject.tag == "Firepit") 
   { 		
		
		flameEmitter.emit = true;
		Debug.Log ("I'm on FIRE"); 
		yield WaitForSeconds (2);
		Debug.Log ("Oh Wait"); 
		flameEmitter.emit = false;
		Debug.Log ("No i'm fine"); 
   } 
}

with the same error if i colide a second time:

so it seems that .emit = false;
allways destroys the object “Fireball” :evil:

Let’s try this approach. I’m basing this one very closely to the 3D Platforming Tutorial on the site. Hopefully it’ll work.

private var onFire = false;

function Start() {
	var emittedFlames : Component[] = GameObject.Find("Fireball").GetComponents(ParticleEmitter); 

	while(true) {
		for (var p : ParticleEmitter in emittedFlames)
		{
			p.emit = onFire;
		}
	}
}

function OnControllerColliderHit(hit : ControllerColliderHit) 
{    
	if (hit.gameObject.tag == "Firepit") 
	{        	
		onFire = true;
		Debug.Log ("I'm on FIRE"); 
		yield WaitForSeconds (2); 
		Debug.Log ("Oh Wait"); 
		onFire = false;
		Debug.Log ("No i'm fine"); 
	} 
}

IT JUST KILLED UNITY!!!
well not really the whole thing froze when i pressed play
i’ve tried a few times and it produces the same results.
frozen solid…
hmmmm
i get the methodology
and it should work

This is going to be the direct logic but altered to fit the situation. Using the same script base again, but this time I’m gonna go line by line. If this doesn’t work, then we can assume the Unity gods are unhappy with us, and I will track down a sacrificial goat.

Create a new script named FireCollider.js. Put the following code into it and attach it to the same object as the script you provided.

var onFire = false;

function OnControllerColliderHit(hit : ControllerColliderHit) 
{    
	if (hit.gameObject.tag == "Firepit") 
	{        	
		onFire = true;
		Debug.Log ("I'm on FIRE"); 
		yield WaitForSeconds (2); 
		Debug.Log ("Oh Wait"); 
		onFire = false;
		Debug.Log ("No i'm fine"); 
	} 
}

Alter the script we’ve been trying to fix to have this code:

function Start() {
	var emittedFlames : Component[] = GameObject.Find("Fireball").GetComponents(ParticleEmitter); 
   var fireColliderVars : FireCollider = GetComponent(FireCollider);

	for (var p : ParticleEmitter in emittedFlames)
	{
		p.emit = false;
	}

	while(true) {
      var onFire = fireColliderVars.onFire;
		for (var p : ParticleEmitter in emittedFlames)
		{
			p.emit = onFire;
		}
      yield;
	}
}

Maybe that yield was needed all along. Overlooked that last time. Anyways, these 2 scripts mimic the main logic and concepts of the example. There’s an external script that controls the boolean that turns the effect on and off. These gave me no compile errors. Hopefully they will work.

this still kills unity aaaarg
right where’s that goat?

i’m thinking of possibly retrying instantiating the particle emiter object my problem with that was intantiating it as a child of “Player”

just doublechecked and found that i misspelled a script name.

it doesnt freeze unity anymore but it does destroy the object “Fireball” instantly.
so progress maybe

This is the project I was pulling the code from. Give it a good look over (including the PDF). Hopefully it may spark something, like something missing in inspector settings and all.

Unfortunately, I don’t have a lot of experience with particle stuff. It’s on my todo list that never seems to get any shorter.

At least there’s still the goat to use.

I actually had this up in the background for the last few days i’ve been working through the tutorial as an exercise in my spare time it turns out that the Autodestruct box on the Particle Animator was checked :sweat_smile: :evil: sorry for the waste of time but at least this was a good learning exercise and we both just learned 3 new methods to do the same thing :P.
thanks for the help

lol Yeah it was good practice overall. And I know what to look out for when I go to do this.

I’ll be sure to let the goat free… for now.