Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by nilesmac · Apr 01, 2020 at 11:49 AM · enemyenemiesenemy healthhealth-deductionhealth

Enemy dies in editor mode but not in build

Hello. I am using one enemy that has a patrol variation. Normally, the enemy stands still and chases the player when the player comes in radius. I made a version of the enemy that patrols back and forth. In editor mode, everything works perfectly. But when I build and run it the idle enemy dies, but the patrol one is invincible. The knock back works but he won't die. I am very frustrated and confused as to what is happening.

How my project is constructed is the enemy inherits from an Enemy script for health:

 private void Awake()
     {
         health = maxHealth.initialValue;
     }
     private void Start()
     {
         health = maxHealth.initialValue;
     }


 private void TakeDamage(float damage)
 {
     health -= damage;
     if (health <= 0)
     {
         soundSource.PlayOneShot(deathSound);
         DeathEffect();
         
         MakeLoot();
         this.gameObject.SetActive(false);
     }
 }


Then I have a scriptable object that is a float value of 2 that is the health of the enemy. The script 'Wolf' inherits from the Enemy script, and then the paroling version inherits from the 'Wolf' script. They both have the same scritable object. Here is the one for the Wolf enemy:

alt text

Here is the patrol variation in the inspector:

alt text

What would cause this to work in the editor but not on build? I don't get any errors related to my enemies.

health.png (67.0 kB)
health2.png (74.4 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by streeetwalker · Apr 01, 2020 at 12:30 PM

@nilesmac, that is not enough information to go on to give you any meaningful advice. We'd need to see the full scripts for all objects involved.

And what do you mean it 'works in Editor Mode' - you are running the scripts using [ExecuteInEditMode] ?

Comment
Add comment · Show 7 · 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 nilesmac · Apr 01, 2020 at 04:20 PM 0
Share

By editor mode, I mean when you are actually able to edit the game and create it. As opposed to running 'Build and run'. As I am making the game, and hitting play to test it out, everything works fine. Once I Build and Run it, my patrol enemy can not die. I have attached all three files for the Enemy, Wolf, and PatrolWolf.

Here is the third one for the Patrol version of the enemy. The site would not like me attach a third file:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PatrolWolf : Wolf
 {
 
     //By not having start you use the base classes start method
 
     public Transform[] path;
     public int currentPoint;
     public Transform currentGoal;
     public float roundingDistance;
 
 
     public override void CheckDistance()
     {
         if (Vector3.Distance(target.position,
                              transform.position) <= chaseRadius
             && Vector3.Distance(target.position,
                                 transform.position) > attackRadius)
         {
             if (currentState == EnemyState.idle || currentState == EnemyState.walk
                 && currentState != EnemyState.stagger)
             {
                 Vector3 temp = Vector3.$$anonymous$$oveTowards(transform.position,
                                                             target.position,
                                                             moveSpeed * Time.deltaTime);
                 changeAnim(temp - transform.position);
                 myRigidbody.$$anonymous$$ovePosition(temp);
                 //ChangeState(EnemyState.walk);
                 anim.SetBool("wakeUp", true);
             }
         }
         else if (Vector3.Distance(target.position,
                              transform.position) > chaseRadius)
         {
             if (Vector3.Distance(transform.position,
                 path[currentPoint].position) > roundingDistance)
             {
                 Vector3 temp = Vector3.$$anonymous$$oveTowards(transform.position,
                                 path[currentPoint].position,
                                 moveSpeed * Time.deltaTime);
                 changeAnim(temp - transform.position);
                 myRigidbody.$$anonymous$$ovePosition(temp);
             }
             else
             {
                 ChangeGoal();
             }
         }
     }
 
     private void ChangeGoal()
     {
         if (currentPoint == path.Length - 1)
         {
             currentPoint = 0;
             currentGoal = path[0];
         }
         else
         {
             currentPoint++;
             currentGoal = path[currentPoint];
 
         }
     }
 }
 
avatar image streeetwalker nilesmac · Apr 01, 2020 at 04:25 PM 0
Share

@nilesmac, yes, we need to know that too: So it doesn't work in the build. What platform are you testing it on - what's the build target?

avatar image nilesmac streeetwalker · Apr 01, 2020 at 04:28 PM 0
Share

I am running it and building it on/for windows PC.

Show more comments
avatar image
0

Answer by nilesmac · Apr 01, 2020 at 04:16 PM

Here are the other two files.


wolf.txt (2.6 kB)
enemy.txt (2.1 kB)
Comment
Add comment · 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

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

201 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

How To Destroy/Deactivate one enemy without affecting other enemies of the same type? 0 Answers

Why is this script not working? 2 Answers

Damage not working properly 1 Answer

How to rotate the enemy in 2D top down 0 Answers

Enemy damage script is not working 0 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