• 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 justaskin324 · Feb 27, 2015 at 08:47 AM · androidjavascripterrorbuild

game won't work in build

My game wont work when I build it but will in the editor. When its built and i play it on the android I click and it doesn't instatiate the currentObj and a sound keeps repeating even though its supposed ti play once. I dont know whats wrong with it but if it helps I wrote all of the first script(except the raycast) and got the click script online. Is there something wrong with the code or is it a bug with unity. Thanks in advance.

 var allObjs : GameObject[];
 var lives : GameObject[];
 var loseSound : AudioClip;
 var hasPlayed : boolean = false;
 var scoreNumObj : GameObject;
 var highScoreNumObj : GameObject;
 var randomSpawnY = [4.3, -4.1];
 var guideLines : GameObject;
 var guideLines2 : GameObject;
 var guideLineAmount = 3;
 var gameOverObj : GameObject;
 var livesCount : int = 4;
 var moveSpeed = 10;
 var gameOverSpeed = 20;
 var theScore : GameObject;
 var boxIsUp : boolean = false;
 var boxIsDown : boolean = false;
 var boxIsPressed : boolean = false;
 static var boxIsPressed1 : boolean;
 var pos = null;
 var currentObj : GameObject; 
 var oldObj1 : GameObject;
 var oldObj2 : GameObject;
 var oldObj3 : GameObject;
 var oldObj4 : GameObject;
 var oldObj5 : GameObject;
 var oldObj6 : GameObject;
 var oldObj7 : GameObject;
 var oldObj8 : GameObject;
 var oldObj9 : GameObject;
 var oldObj10 : GameObject;
 var o :int;
 var done : boolean = false;
 var doneCheck : boolean = true;
 static var score : float = 0;
 var sscore : int;
 var bestScoreCheck : boolean = false;
 var oldObjCheck : boolean = false;
 var gameOver : boolean = false;
 var boxLimitTop = -0.2;
 var boxLimitBottom = 0.2;
 private var hit: RaycastHit;
 function Start () {
 
 }
 
 function Update () {
     boxIsPressed = boxIsPressed1;
     
     sscore = score;
     
     if(currentObj){
         var newPosition : int = (currentObj.transform.position.x + 2);
         pos = newPosition;
     }
     
     var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     
     if(boxIsPressed){
         oldObj10 = oldObj9.gameObject;
         oldObj9 = oldObj8.gameObject;
         oldObj8 = oldObj7.gameObject;
         oldObj7 = oldObj6.gameObject;
         oldObj6 = oldObj5.gameObject;
         oldObj5 = oldObj4.gameObject;
         oldObj4 = oldObj3.gameObject;
         oldObj3 = oldObj2.gameObject;
         oldObj2 = oldObj1.gameObject;
         oldObj1 = currentObj.gameObject;
         currentObj = Instantiate(allObjs[Random.Range(0,allObjs.Length)],Vector3(pos,randomSpawnY[Random.Range(0,randomSpawnY.Length)],0),Quaternion.identity);
         moveSpeed = Random.Range(7,11);
         boxIsUp = false;
         boxIsDown = false;
         if(score > 4){
             Camera.main.transform.position.x = currentObj.transform.position.x - 2;
         }
         if(gameOver == false){
         score += 1;
         }
         if(oldObj2 != null && oldObj1 != null && oldObj2.transform.position.y - oldObj1.transform.position.y >= boxLimitBottom || oldObj2 != null && oldObj1 != null && oldObj2.transform.position.y - oldObj1.transform.position.y <= boxLimitTop){
             livesCount -= 1;            
         }
             
         boxIsPressed = false;
         boxIsPressed1 = false;        
     }
     if(boxIsUp && currentObj){
         currentObj.transform.Translate(Vector3.down * moveSpeed * Time.deltaTime);
     }
     if(boxIsDown && currentObj){
         currentObj.transform.Translate(Vector3.up * moveSpeed * Time.deltaTime);
     }
     if(currentObj != null && currentObj.transform.position.y >= 4.1 ){
         boxIsUp = true;
         boxIsDown = false;
     }
     if(currentObj != null && currentObj.transform.position.y <= -4.04 ){
         boxIsUp = false;
         boxIsDown = true;
     }
     
     if(oldObj1){
         if(guideLines && guideLines2){
             guideLines.transform.position.y = oldObj1.transform.position.y + 1.45;
             guideLines2.transform.position.y = oldObj1.transform.position.y - 1.15;    
         }
     }
     if(score >= 3){
         Destroy(guideLines);
         Destroy(guideLines2);    
     }
     if(livesCount == 3){
         Destroy(lives[0]);
     }
     if(livesCount == 2){
         Destroy(lives[1]);
     }
     if(livesCount == 1){
         Destroy(lives[2]);
     }
     if(livesCount == 0){
         bestScoreCheck = true;
         oldObjCheck = true;
         gameOver = true;
     }
     if(gameOver && hasPlayed == false){
          hasPlayed = true;
          audio.PlayOneShot(loseSound);    
     }
     if(bestScoreCheck == true && gameOverObj.transform.position.y >= 8.3){
         bestScoreCheck = false;
         done = true;    
     }
     if(oldObj1 && oldObj1.transform.position.y <= -15){
         oldObjCheck = false;    
     }
     if(gameOver){
         Destroy(currentObj);
         Destroy(theScore);
         if(gameOverObj&& bestScoreCheck){
             gameOverObj.transform.Translate(Vector3.up * gameOverSpeed * Time.deltaTime);
         }
         if(oldObjCheck){
             if(oldObj1){
                 oldObj1.transform.Translate(Vector3.down * gameOverSpeed * Time.deltaTime);
             }
             if(oldObj2){
                 oldObj2.transform.Translate(Vector3.down * gameOverSpeed * Time.deltaTime);
             }
             if(oldObj3){
                 oldObj3.transform.Translate(Vector3.down * gameOverSpeed * Time.deltaTime);
             }
             if(oldObj4){
                 oldObj4.transform.Translate(Vector3.down * gameOverSpeed * Time.deltaTime);
             }
             if(oldObj5){
                 oldObj5.transform.Translate(Vector3.down * gameOverSpeed * Time.deltaTime);
             }
             if(oldObj6){
                 oldObj6.transform.Translate(Vector3.down * gameOverSpeed * Time.deltaTime);
             }
             if(oldObj7){    
                 oldObj7.transform.Translate(Vector3.down * gameOverSpeed * Time.deltaTime);
             }
             if(oldObj8){
                 oldObj8.transform.Translate(Vector3.down * gameOverSpeed * Time.deltaTime);
             }
             if(oldObj9){
                 oldObj9.transform.Translate(Vector3.down * gameOverSpeed * Time.deltaTime);
             }
             if(oldObj10){
                 oldObj10.transform.Translate(Vector3.down * gameOverSpeed * Time.deltaTime);
             }
             
         }
     }
     if(done && doneCheck){
         doneCheck = false;
         Instantiate(scoreNumObj,Vector3(0.62,0.52,0),Quaternion.identity);
         Instantiate(highScoreNumObj,Vector3(0.62,0.36,0),Quaternion.identity);            
     }
 
     if(gameOver){
         if (Input.GetMouseButtonUp(0))
         {    
             if(Physics.Raycast (ray, hit, Mathf.Infinity)){
                 if(hit.collider.tag == "re-start"){
                     Application.LoadLevel (1);
                     boxMoving.score = 0;
                 }
             }    
         }
     }    
 }
 
 

heres the click script: #pragma strict

  var platform : RuntimePlatform = Application.platform;
  
  function Update(){
      if(platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer){
          if(Input.touchCount > 0) {
              if(Input.GetTouch(0).phase == TouchPhase.Began){
                  checkTouch(Input.GetTouch(0).position);
              }
          }
      }else if(platform == RuntimePlatform.WindowsEditor){
          if(Input.GetMouseButtonDown(0)) {
              checkTouch(Input.mousePosition);
          }
      }
  }
  
  function checkTouch(pos){
      var wp : Vector3 = Camera.main.ScreenToWorldPoint(pos);
      var touchPos : Vector2 = new Vector2(wp.x, wp.y);
      var hit = Physics2D.OverlapPoint(touchPos);
      
      if(hit){
          Debug.Log(hit.transform.gameObject.name);
          hit.transform.gameObject.SendMessage('Clicked',0,SendMessageOptions.DontRequireReceiver);
      }
  }
 function Clicked(){
     boxMoving.boxIsPressed1 = true;
 }
 
Comment
Add comment · Show 1
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 meat5000 ♦ · Feb 27, 2015 at 03:19 AM 0
Share

There is something wrong with your gameover condition. You object is being instantiated but it is being destroyed. Your oneshot sound spam$$anonymous$$g away is what tells me this.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Compiler error while switching to android 1 Answer

Access JavaScript variables on c# script (Android build fails!) 1 Answer

What does this error even mean? 1 Answer

Having issue building apk 1 Answer

Android SDK does not include error 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