Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 DimSour · Nov 09, 2016 at 06:34 PM · iosbuildandroid buildlagfreeze

game freezes on devices but plays well on pc.

Hi.i've build a game and it plays with no problems on pc and android simulator but when i test it on devices it freezes when the bullet prefab collides with the enemy.it goes down to 1-2 fps or smth or sometimes it randomly freezes.What can be the cause? devices tested:iphone 6s, samsung galaxy s6.

Comment
Add comment · Show 3
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 Landern · Nov 09, 2016 at 06:51 PM 0
Share

What can be the cause?

Poorly coded expectations? While loops that take forever to end? Etc.

Best to post your code as it relates to the collision.

avatar image DimSour Landern · Nov 09, 2016 at 07:13 PM 0
Share

this is the code for the collide (the pirate and the slash one work fine game freezes when the bullet collides)

  void OnTriggerEnter2D(Collider2D col)
         {
             if (col.gameObject.name == "pirate")
             {
                 AudioSource audio = GetComponent<AudioSource>();
                 audio.Play();           
                 nikise = true;
                 Destroy(this.gameObject,0.3f);
                 Destroy(transform.parent.gameObject,0.3f);
             }
             if(col.gameObject== bullet)
             {
                 tempHealth -= 1;
             }
             if (col.gameObject.name == "slash")
             {
                 swordCol = true;
                 tempHealth -= 3;
             }
         }

(In the update i have this) bullet = GameObject.Find("Bullet(Clone)"); (i also tried "col.gameObject== Bullet(Clone)");

this code is in the bullet for it to be destroyed if it collides with the monkey

 void OnTriggerEnter2D(Collider2D col)
     {
         if (col.gameObject.name == "monkey")
         {
             Destroy(this.gameObject);
         }
     }




avatar image aditya007 DimSour · Nov 10, 2016 at 06:25 AM 0
Share

You have the code bullet = GameObject.Find("Bullet(Clone)"); in the Update function?. That might be the issue because GameObject.Find can be super slow depending upon the number of objects present in hierarchy. And you're calling it in update, which makes things worse.

Consider using tags for finding gameObjects. And don't call it in Update function.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DimSour · Nov 10, 2016 at 01:45 PM

so the problem was my enemy's health bar script

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class MonkeyHealthBar : MonoBehaviour {
 
     public float fillAmount;
     public float tempHealth;
     public float maxHealth;
     
     public monkey monkeyScript;
     public Image content;
 
     void Update ()
     {
         tempHealth = monkeyScript.tempHealth;
         maxHealth = monkeyScript.maxHealth;
         fillAmount = tempHealth / maxHealth;
         content.fillAmount = fillAmount;
 
     }
 }
 


does anyone know the reason?? @aditya007 @Landern

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

98 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

Related Questions

Unity 5 keeps freezing when I try to build my Android project. 1 Answer

Building .APK Apps using a Unity App 0 Answers

Help. About IPA size, my empty project have 46MB... 0 Answers

Problem with building on Android 0 Answers

Unity says that I'm missing my NDK and SDK libraries, but I have them installed via Unity hub? 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