- Home /
could someone tell me whats wrong with this script?
I've been making a FPS and I've been trying to get my M16 Model to fire. My script is below
var range = 100.0; var fireRate = 0.05; var force = 10.0; var damage = 5.0; var bulletsPerClip = 40; var clips = 20; var reloadTime = 0.5; private var hitParticles : ParticleEmitter; var muzzleFlash : Renderer; private var bulletsLeft : int = 0; private var nextFireTime = 0.0; private var m_LastFrameShot = -1; function Start () { hitParticles = GetComponentInChildren(ParticleEmitter); // We don't want to emit particles all the time, only when we hit something. if (hitParticles) hitParticles.emit = false; bulletsLeft = bulletsPerClip;
function LateUpdate(){ } if (muzzleFlash) { // We shot this frame, enable the muzzle flash if (m_LastFrameShot == Time.frameCount) { muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.Range(0, 359), Vector3.forward); muzzleFlash.enabled = true; if (audio) { if (!audio.isPlaying) audio.Play(); audio.loop = true; } } // We didn't, disable the muzzle flash else { muzzleFlash.enabled = false; enabled = false; // Play sound if (audio) { audio.loop = false; } } }
Could someone tell me what is wrong with it beacause I'm at a loss at what to do
you forgot to add closing brackets after the else statement near the end, right before if(audio)....
my error messeges are "Found LateUpdate" type of thing
This is what is says exactly Assets/NewBehaviourScript 2.js(21,10): BCE0044: expecting (, found 'LateUpdate'.
Answer by oliver-jones · Nov 17, 2010 at 01:33 AM
Also, you are missing a bracket from the Start function:
function Start ()
{
hitParticles = GetComponentInChildren(ParticleEmitter);
// We don't want to emit particles all the time, only when we hit something.
if (hitParticles)
hitParticles.emit = false;
bulletsLeft = bulletsPerClip;
}
Good answers - but please note, unless you're offering an alternative and different solution to the question, you should generally append extra information to your original question using the "edit" feature, or by adding comments. This is so there is a single specific question which can be marked as "accepted".
Answer by oliver-jones · Nov 17, 2010 at 01:32 AM
Where your function LateUpdate is, replace all that with this:
function LateUpdate()
{
if (muzzleFlash)
{
// We shot this frame, enable the muzzle flash
if (m_LastFrameShot == Time.frameCount)
{
muzzleFlash.transform.localRotation =
Quaternion.AngleAxis(Random.Range(0, 359), Vector3.forward);
muzzleFlash.enabled = true;
if (audio)
{
if (!audio.isPlaying)
audio.Play();
audio.loop = true;
}
}
// We didn't, disable the muzzle flash
else
{
muzzleFlash.enabled = false;
enabled = false;
// Play sound
if (audio)
{
audio.loop = false;
}
}
}
}
You had a few brackets in the wrong place
Your answer
Follow this Question
Related Questions
HELP ME PLEASE!----------------------------!? 1 Answer
scripting problem with if statements 1 Answer
BCE0044: expecting }, found 'class' alond with BCE0044: expecting EOF, found 'Card' 1 Answer
Problems with my grenade PLEASE HELP! 1 Answer
Getting several BCE0044 compiler errors for OnCollisionEnter. Is my syntax wrong? 4 Answers