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
0
Question by FatalNightmare · Jun 30, 2013 at 11:40 PM · javascriptbuildcrashenemy

Once game is built, it crashes when enemy dies.

Hey guys, so I got this problem; when I build and run my game and kill an enemy my game just closes like it crashed. This happens everytime with every enemy. When i play the exact same game in Unity it doesn't crash when I kill an enemy. What could cause this? Anything I should look into? Do you need to see any code?

UPDATE: It has to do something with these two codes, because I have both of them only on crates, and when I try to destroy the crates my game crashes. So that's good I guess...

UPDATES AGAIN: I'm pretty sure it has to do with the health code, I took off the destroy object code and it still crashed.

Code attached to enemy: Default Untiy3d Health Code

 #pragma strict
 
 public var maxHealth : float = 100.0;
 public var health : float = 100.0;
 public var regenerateSpeed : float = 0.0;
 public var invincible : boolean = false;
 public var dead : boolean = false;
 
 public var damagePrefab : GameObject;
 public var damageEffectTransform : Transform;
 public var damageEffectMultiplier : float = 1.0;
 public var damageEffectCentered : boolean = true;
 
 public var scorchMarkPrefab : GameObject = null;
 private var scorchMark : GameObject = null;
 
 public var damageSignals : SignalSender;
 public var dieSignals : SignalSender;
 
 private var lastDamageTime : float = 0;
 private var damageEffect : ParticleEmitter;
 private var damageEffectCenterYOffset : float;
 
 private var colliderRadiusHeuristic : float = 1.0;
 
 
 function Awake () {
     enabled = false;
     if (damagePrefab) {
         if (damageEffectTransform == null)
             damageEffectTransform = transform;
         var effect : GameObject = Spawner.Spawn (damagePrefab, Vector3.zero, Quaternion.identity);
         effect.transform.parent = damageEffectTransform;
         effect.transform.localPosition = Vector3.zero;
         damageEffect = effect.particleEmitter;
         var tempSize : Vector2 = Vector2(collider.bounds.extents.x,collider.bounds.extents.z);
         colliderRadiusHeuristic = tempSize.magnitude * 0.5;
         damageEffectCenterYOffset = collider.bounds.extents.y;
         
     }
     if (scorchMarkPrefab) {
         scorchMark = GameObject.Instantiate(scorchMarkPrefab, Vector3.zero, Quaternion.identity);
         scorchMark.active = false;
     }
 }
 
 function OnDamage (amount : float, fromDirection : Vector3) {
     // Take no damage if invincible, dead, or if the damage is zero
     if(invincible)
         return;
     if (dead)
         return;
     if (amount <= 0)
         return;
     
     // Decrease health by damage and send damage signals
     
     // @HACK: this hack will be removed for the final game
     //  but makes playing and showing certain areas in the
     //  game a lot easier
     /*    
     #if !UNITY_IPHONE && !UNITY_ANDROID
     if(gameObject.tag != "Player")
         amount *= 10.0;
     #endif
     */
     
     health -= amount;
     damageSignals.SendSignals (this);
     lastDamageTime = Time.time;
     
     // Enable so the Update function will be called
     // if regeneration is enabled
     if (regenerateSpeed > 0)
         enabled = true;
     
     // Show damage effect if there is one
     if (damageEffect) {
         damageEffect.transform.rotation = Quaternion.LookRotation (fromDirection, Vector3.up);
         if(!damageEffectCentered) {
             var dir : Vector3 = fromDirection;
             dir.y = 0.0;
             damageEffect.transform.position = (transform.position + Vector3.up * damageEffectCenterYOffset) + colliderRadiusHeuristic * dir;
         }
         // @NOTE: due to popular demand (ethan, storm) we decided
         // to make the amount damage independent ...
         // var particleAmount = Random.Range (damageEffect.minEmission, damageEffect.maxEmission + 1);
         // particleAmount = particleAmount * amount * damageEffectMultiplier;
         damageEffect.Emit();// (particleAmount);
     }
     
     // Die if no health left
     if (health <= 0) {
         health = 0;
         dead = true;
         dieSignals.SendSignals (this);
         enabled = false;
         Application.Quit();
         
         // scorch marks
         if (scorchMark) {
             scorchMark.active = true;
             // @NOTE: maybe we can justify a raycast here so we can place the mark
             // on slopes with proper normal alignments
             // @TODO: spawn a yield Sub() to handle placement, as we can
             // spread calculations over several frames => cheap in total
             var scorchPosition : Vector3 = collider.ClosestPointOnBounds (transform.position - Vector3.up * 100);
             scorchMark.transform.position = scorchPosition + Vector3.up * 0.1;
             scorchMark.transform.eulerAngles.y = Random.Range (0.0, 90.0);
         }
     }
 }
 
 function OnEnable () {
     Regenerate ();    
 }
 
 // Regenerate health
 
 function Regenerate () {
     if (regenerateSpeed > 0.0f) {
         while (enabled) {
             if (Time.time > lastDamageTime + 3) {
                 health += regenerateSpeed;
                 
                 yield;
                 
                 if (health >= maxHealth) {
                     health = maxHealth;
                     enabled = false;
                 }
             }
             yield WaitForSeconds (1.0f);
         }
     }
     
     
 }
 
 /*function OnTriggerEnter(other : Collider){
     if(other.tag == "Health"){
     health += 0.1;
        Destroy(other.gameObject);
        }
 
        */

***Destroy Object code

 #pragma strict
 
 var objectToDestroy : GameObject;
 
 function OnSignal () {
     Spawner.Destroy (objectToDestroy);
 }

That's it, plus a movement code but I don't think that's necessary.

Comment
Add comment · Show 5
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 clunk47 · Jun 30, 2013 at 11:44 PM 0
Share

Need details brotha. Need to know what script you have attached to the enemy and the player and / or camera. It would be good to post any code attached to the enemies. That way we can see if there is something wrong with a script. You're obviously not getting any errors in the compiler, but are you getting any warnings at all in the console? Include any info like this and your issue should be resolved in a timely manner :)

avatar image FatalNightmare · Jul 01, 2013 at 12:00 AM 0
Share

Okay, my post has been edited.

avatar image Owen-Reynolds · Jul 01, 2013 at 12:08 AM 0
Share

When you run in the editor and kill something, do you get anything red in the error window? In editor mode, errors will skip some code and go on, so you may not notice. In the build, the same error will crash.

avatar image FatalNightmare · Jul 01, 2013 at 12:13 AM 0
Share

No I get no new red error codes when I kill the enemy. I get some when it spawns but it is just simple need to have a death explosion and stuff. Which I do add and it still crashes the game.

avatar image clunk47 · Jul 01, 2013 at 12:13 AM 0
Share

Accept the answer below by Jamora. Application.Quit() has no effect in the editor, but does in standalone application. It kills the process.

1 Reply

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

Answer by Jamora · Jul 01, 2013 at 12:11 AM

You have Application.Quit(); in line 98. Remove that and everything should work. It does nothing in the Editor, so that could be why your standalones seems to 'crash'.

Comment
Add comment · Show 1 · 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 FatalNightmare · Jul 01, 2013 at 12:17 AM 1
Share

OH $$anonymous$$Y GOSH! HOW COULD I HAVE $$anonymous$$ISSED THAT! Thank you so much for pointing it out and being kind that I missed something like that! Stay awesome my friend!

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does my pathfinding script keep crashing Unity? 1 Answer

Distribute terrain in zones 3 Answers

Game Crash When Changing Scene 1 Answer

I need some health with my health/enemy script 0 Answers

Only one cloned enemy shoots 2 Answers


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