• 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 Fetdressing · May 15, 2013 at 04:07 PM · build-error

Script not working when I build and run

Hey! Some of my scripts just wont work when I build and run, this is not the only one but if you have any clues that would be awsome!

 private var anyTargetLeft;
 private var target : GameObject;    
 public var targetPos : Vector3; //to be able to jump(why its public)
 public var damage : int = 15;
 
 private var findTarget : boolean = true;
 
 public var moveSpeed : float = 10;
 private var grounded : boolean = true;
 
 function Start () {
 //animation.Play("Walk");
    }
 
 function Update () {
 
 
 
 //Destroys this script so it wont lagg when you loose
     var anyTargetLeft = GameObject.FindGameObjectWithTag("Tower");
 if(anyTargetLeft == null){
     
     Destroy(this);
 }
 
 if(target.gameObject == null || GameObject.FindGameObjectWithTag("MiniTower")){
     findTarget = true;
 }
 
 if(findTarget == true){
 target = GameObject.FindGameObjectWithTag("MiniTower");
 if(target == null){
     target = GameObject.FindGameObjectWithTag("Tower");
     findTarget = false;
 }
 findTarget = false;
 }
 targetPos = Vector3(target.transform.position.x,this.transform.position.y,target.transform.position.z);
 
 this.transform.LookAt(targetPos);
 this.gameObject.transform.Translate(Vector3(0,0,Time.deltaTime * moveSpeed));
 
 
 
 }
 
 function OnCollisionEnter(targetHit : Collision){
 
 
 
 
 //main tower
     if(targetHit.gameObject.tag == "Tower"){
         var objectHit = targetHit.gameObject;
         objectHit.GetComponent(HPTower).towerApplyDMG(damage); //gånger gamelvl senare
         Debug.Log("Has exploded at tower");
         Destroy(this.gameObject);
     }
     
     
     //small towers
     if(targetHit.gameObject.tag == "MiniTower"){
         objectHit = targetHit.gameObject;
         objectHit.GetComponent(MiniTowerHP).towerApplyDMG(damage); //gånger gamelvl senare
         Debug.Log("Has exploded at tower");
         Destroy(this.gameObject);
     }
 }
 //ice canon
 function speedReduction(reduceSpeed : float){ //retriew float from Projectile.js
     
       //so the movementspeed wont pass under 0
         moveSpeed = moveSpeed - reduceSpeed;
         if(moveSpeed <= 0.5){
             moveSpeed = 0.5;
         }
         
     
 }

This is the whole script. I put this script on my enemies and it works just fine in unity. When I build and run the enemies just wont move, they just stand still. //Simon

Comment
Add comment · Show 6
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 ExTheSea · May 15, 2013 at 05:56 PM 0
Share

Currently a lot of problem (me included) had the the problem that a script suddenly stopped working when they made a Build.

The solution I found and then told everyone else was to create a new script. copy the code from the old one and then use the new one ins$$anonymous$$d. I don't know if that works in your case but it might be worth checking.

avatar image Fetdressing · May 16, 2013 at 09:11 PM 0
Share

Yea, didn't work :( I tried reimporting everything aswell. Seems like there are more having this problem.

avatar image ExTheSea · May 17, 2013 at 04:08 PM 0
Share

Did it really not work? Everytime someone else had this problem it worked this way. Did you also remove the old "corrupted" script?

Btw. To check if you even have a corrupted script make a devolpment build so that you have a console. Then when you run the build it should say something in red about corrupted files.

avatar image Fetdressing · May 18, 2013 at 05:34 PM 0
Share

Ahh thanks, they say that they can't find an object. I had the same problem on another script which was also some kind of AI and all I had to do was give it a .gameObject after a line. It seems as if when I build I need to be more specific about what object or thing I am meaning for it to find it. I tried adding to this script and being more specific about what I meant but can't find it.

avatar image whydoidoit · May 18, 2013 at 08:26 PM 0
Share

You should Debug.Log at the destroy point and see if it's getting called in the built version

Show more comments

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers

How can I stop the variable values reverting to its default values after being built? 1 Answer

windows sdk installed but get error 1 Answer

Android build error unity 5.4 b15 0 Answers

Unity building to WebGL crashes computer when building libraries or native JS files 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