- Home /
error in a script for jet pack for plane
So im trying to get a "boost" particle effect working for a fighter. Now ive looked at the scripting reference and i have not been able to figure this one out. Can anyone help me
> function Update () { if
> (Input.GetButton ("Fire1") {
> particleEmitter.emit = true; }
> particleEmitter.emit = false; }
Error Console Message:
Assets/afterburner effect.js(3,39): BCE0044: expecting ), found '{'.
Assets/afterburner effect.js(8,1): BCE0044: expecting EOF, found '}'.
The importer for asset Assets/afterburner scirpt.js (MonoImporter) did not generate a MD4 digest. (i didnt get this last message)
can anyone help me understand this
Answer by syclamoth · Oct 04, 2011 at 01:59 AM
There are multiple issues here-
1. You don't have enough brackets!
In your if statement, you need to close off the condition properly!
if(Input.GetButton ("Fire1")) {
// do stuff
}
2. Even if it worked, you would immediately turn it back off again!
When you write an if statement, it executes the bits inside the curly brackets only in the case where the condition returns true. However, as soon as you get out of those brackets, it always executes the next bit! You should be using an 'else' statement, afterwards--
if(Input.GetButton ("Fire1")) {
particleEmitter.emit = true;
} else {
particleEmitter.emit = false;
}
That way, it only disables the particles if you aren't holding the fire button.
Give that a shot!
@rohan bhangui: ins$$anonymous$$d of posting a comment as answer you could upvote this answer and if it solves your problems mark it as "the right answer".
btw: such simple boolean statements can also be written as:
particleEmitter.emit = Input.GetButton ("Fire1");
@Bunny83 Oh yeah, forgot about that- for something as simple as this, that'd be perfect!
Your answer
Follow this Question
Related Questions
Particle Emitter error, Missing reference exception. 1 Answer
Casting error on multiple emitters 3 Answers
How to enable a ParticleEmitter in scripting 2 Answers
How to fade out an object with no renderer (and how is that even possible?!) -1 Answers
I keep floating when i want gravity and I have some code can you guys help me please 0 Answers