Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by oliver-jones · Apr 25, 2011 at 01:06 PM · updateframeratemuzzleflash

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) &amp;&amp; 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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Apr 25, 2011 at 01:10 PM 0
Share

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

avatar image oliver-jones · Apr 25, 2011 at 01:20 PM 0
Share

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

2 Replies

· Add your reply
  • Sort: 
avatar image
9
Best Answer

Answer by Eric5h5 · Apr 28, 2011 at 12:19 PM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ashkan_gc · May 02, 2011 at 02:28 AM 0
Share

it seems that you are right eric

avatar image oliver-jones · May 03, 2011 at 11:32 PM 0
Share

how would one do that?

avatar image Eric5h5 · May 03, 2011 at 11:45 PM 0
Share

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

avatar image
-3

Answer by tomekkie · Apr 25, 2011 at 02:26 PM

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

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oliver-jones · Apr 25, 2011 at 02:39 PM 0
Share

Does that have anything to do with my problem?

avatar image Clem · Apr 28, 2011 at 09:35 AM 0
Share

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

avatar image Eric5h5 · Apr 28, 2011 at 12:13 PM 0
Share

@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.

avatar image Ashkan_gc · May 02, 2011 at 02:26 AM 0
Share

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

avatar image Eric5h5 · May 02, 2011 at 02:51 AM 0
Share

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

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Character,Camera,Updates,Frame Rates,Jitter&Stutter, I need some explanations. 0 Answers

Animating GUI Texture - Help 4 Answers

Boolean Trouble, Please help....Boolean does not flip another boolean 0 Answers

Game frame rate on macbook acceptable for iphone ? 1 Answer

Framerate independent character movement 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges