x


Muzzle Flash Works In Editor - But Not Build??

Hello,

I have a turret that has a muzzle flash that is on for one frame. In the editor, you can clearly see that the muzzle flash when it fires, whereas in the build, you only see it sometimes. I'm not sure if its to do with the LateUpdate? or FrameCounting? I'm not really familiar with all that. Below is the code that controls the muzzle flash:

function LateUpdate() {
    var ExternalResearch : TurretResearch;
    ExternalResearch = gameObject.GetComponent("TurretResearch");

    if (ExternalResearch.CurrentSelectedFlash) { //muzzleFlash
        if (m_LastFrameShot == Time.frameCount) {
            audio.clip = TurretSound;
            audio.Play();
            ExternalResearch.CurrentSelectedFlash.gameObject.SetActiveRecursively(true);
        } else {
            ExternalResearch.CurrentSelectedFlash.gameObject.SetActiveRecursively(false);
        }
    }
}

function FireOneShot () {
    var direction = transform.TransformDirection(Vector3.forward);
    var hit : RaycastHit;
    var localOffset = transform.position + transform.up * 2;
    var layerMask = 1 << 10;
    layerMask = ~layerMask;

    // Did we hit anything?
    //transform.position + transform.up * 10
    if (Physics.Raycast (localOffset, direction, hit, 90000, layerMask) && MachineGun == true) {
         Debug.DrawLine (localOffset, hit.point, Color.yellow);
        // Apply a force to the rigidbody we hit
        if (hit.rigidbody)
            hit.rigidbody.AddForceAtPosition(force * direction, hit.point);

        // Place the particle system for spawing out of place where we hit the surface!
        // And spawn a couple of particles
        if (hitParticles) {
            hitParticles.transform.position = hit.point;
            hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
            hitParticles.Emit();
        }

        // Send a damage message to the hit object          
        hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    }

    bulletsLeft--;

    // Register that we shot this frame,
    // so that the LateUpdate function enabled the muzzleflash renderer for one frame
    m_LastFrameShot = Time.frameCount;
    enabled = true;

    // Reload gun in reload Time        
    if (bulletsLeft == 0)
        Reload();           
}

Any reason why its doing that? I would appreciate any help.

Thanks folks.

more ▼

asked Apr 25 '11 at 01:06 PM

oliver-jones gravatar image

oliver-jones
2.5k 205 225 253

Can you hear the audio being played in the build? When do you set m_LastFrameShot?

Apr 25 '11 at 01:10 PM Statement ♦♦

Updated script. And Yeah - I can still hear my audio.

Apr 25 '11 at 01:20 PM oliver-jones
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You should probably make the flash last for a specified period of time (1/20th of a second or something), rather than one frame. The game runs faster in a build than the editor, and if you're getting, say, 150 fps and your screen refresh is 60Hz, then it's somewhat likely a single-frame flash wouldn't even be drawn by the monitor.

more ▼

answered Apr 28 '11 at 12:19 PM

Eric5h5 gravatar image

Eric5h5
80k 41 131 518

it seems that you are right eric

May 02 '11 at 02:28 AM Ashkan_gc

how would one do that?

May 03 '11 at 11:32 PM oliver-jones

Any number of ways, yield WaitForSeconds probably being the simplest.

May 03 '11 at 11:45 PM Eric5h5
(comments are locked)
10|3000 characters needed characters left

Do not use editor classes like Debug. They are only for using in the Unity editor and are not available at runtime.

more ▼

answered Apr 25 '11 at 02:26 PM

tomekkie gravatar image

tomekkie
33 9 9 16

Does that have anything to do with my problem?

Apr 25 '11 at 02:39 PM oliver-jones

As far as I know Debug is an Engine class so this should not be the problem.

Apr 28 '11 at 09:35 AM Clem

@tomekkie: That's not actually correct; Debug.Log works fine in a build, and Debug.isDebugBuild is intended to be used in a build (it just returns true in the editor). DrawLine/DrawRay don't though.

Apr 28 '11 at 12:13 PM Eric5h5

if you check the debug build checkbox when building then isdebug will return true in your build too.

May 02 '11 at 02:26 AM Ashkan_gc

@Ashkan: yes, that's what isDebugBuild is for.

May 02 '11 at 02:51 AM Eric5h5
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x492
x92
x35
x24

asked: Apr 25 '11 at 01:06 PM

Seen: 1173 times

Last Updated: Apr 28 '11 at 09:29 AM