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 ReinholdRunner · May 03, 2015 at 04:39 PM · touchperformanceperformance optimization

Android 3d game - laggy, bad performance

Hey,

currently I'm developing a game with touch controls (5 Gui-buttons) but sadly it's really laggy :/ Right now there aren't that many objects in my scene nor big textures nor crazy lightning (all materials are unlit)

There's a Screenshot of the Performance Profiler ↓

alt text

Obviously it has something to do with the touchbuttons

.

Update-function of the LocThroww.cs - Script:

 if (isPressed == true){
             guiTexture.color = Color.gray;
         }
         else{
             guiTexture.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
         }
         
         if (Screen.dpi != 0) {
             dpi = Screen.dpi * 0.000006f;
         }
         else{
             dpi = 1000;
         }
         guiTexture.pixelInset  = new Rect(- 105000 * dpi, 130000 * dpi, 100000 * dpi, 100000 * dpi);

.

My Touchmanagerscript if needed:

 using UnityEngine;
 using System.Collections;
 
 public class Touchmanager : MonoBehaviour {
 
     public static int currTouch = 0;//so other scripts can know what touch is currently on screen
     private Ray ray;//this will be the ray that we cast from our touch into the scene
     private RaycastHit rayHitInfo = new RaycastHit();//return the info of the object that was hit by the ray
     [HideInInspector]
     public int touch2Watch = 64;
     
     void Update () 
     {
         if(Input.touches.Length <= 0)
         {
             //if no touches then execute this code
         }
         else //if there is a touch
         {
             //loop through all the the touches on screen
             for(int i = 0; i < Input.touchCount; i++)
             {
                 currTouch = i;
                 Debug.Log(currTouch);
                 //executes this code for current touch (i) on screen
                 if(this.guiTexture.HitTest(Input.GetTouch(i).position)){
 
                     if(Input.GetTouch(i).phase == TouchPhase.Began)
                     {
                         this.SendMessage("OnTouchBegan");
                     }
                     if(Input.GetTouch(i).phase == TouchPhase.Ended)
                     {
                         this.SendMessage("OnTouchEnded");
                     }
                     if(Input.GetTouch(i).phase == TouchPhase.Moved)
                     {
                         this.SendMessage("OnTouchMoved");
                     }
                     if(Input.GetTouch(i).phase == TouchPhase.Stationary)
                     {
                         this.SendMessage("OnTouchStayed");
                     }
                     if(Input.GetTouch(i).phase == TouchPhase.Canceled)
                     {
                         this.SendMessage("OnTouchCanceled");
                     }
                 }
                 //outside so it doesn't require the touch to be over the guitexture
                 ray = Camera.mainCamera.ScreenPointToRay(Input.GetTouch(i).position);//creates ray from screen point position
                 switch(Input.GetTouch(i).phase)
                 {
                 case TouchPhase.Began:
                     //OnTouchBeganAnywhere();
                     this.SendMessage("OnTouchBeganAnyWhere");
                     if(Physics.Raycast(ray, out rayHitInfo))
                         rayHitInfo.transform.gameObject.SendMessage("OnTouchBegan3D");
                     break;
                 case TouchPhase.Ended:
                     //OnTouchEndedAnywhere();
                     this.SendMessage("OnTouchEndedAnywhere");
                     if(Physics.Raycast(ray, out rayHitInfo))
                         rayHitInfo.transform.gameObject.SendMessage("OnTouchEnded3D");
                     break;
                 case TouchPhase.Moved:
                     //OnTouchMovedAnywhere();
                     this.SendMessage("OnTouchMovedAnywhere");
                     if(Physics.Raycast(ray, out rayHitInfo))
                         rayHitInfo.transform.gameObject.SendMessage("OnTouchMoved3D");
                     break;
                 case TouchPhase.Stationary:
                     //OnTouchStayedAnywhere();
                     this.SendMessage("OnTouchStayedAnywhere");
                     if(Physics.Raycast(ray, out rayHitInfo))
                         rayHitInfo.transform.gameObject.SendMessage("OnTouchStayed3D");
                     break;
                 }
             }
         }
     }
 }

.

I'd be really really happy if someone could help me with my problem :/

thanks in advance :)

performance-problem.png (179.0 kB)
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 Dave-Hampson ♦♦ · May 04, 2015 at 07:49 AM 0
Share

What is LocThroww.cs doing exactly?

avatar image ReinholdRunner · May 04, 2015 at 06:55 PM 0
Share

Both scripts are connected to a guitexture which changes the color as long as it is touched. The variable "isPressed" is set to static in order to get used by another script...

avatar image tanoshimi · May 04, 2015 at 08:08 PM 0
Share

"The variable "isPressed" is set to static in order to get used by another script" - that's not what static is for! That's what public is for... https://unity3d.com/learn/tutorials/modules/beginner/scripting/getcomponent

avatar image ReinholdRunner · May 04, 2015 at 08:16 PM 0
Share

Oh, thanks... :´D good to know

But my game is still laggy. Any Ideas why the "LocThroww"-Script uses that much CPU? :/

avatar image screenname_taken · May 04, 2015 at 09:24 PM 0
Share

honestly, i saw scripts taking too much cpu time when they are multiplying numbers with many 0s after the point. And what are you doing with so high dpi numbers?

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Best way to do touch in with Unity2D? 0 Answers

Reading Profiler Results 1 Answer

Random lag spikes any time processor intensive tasks a scene 0 Answers

Unity warnings outside of editor. Does it impact application performance? 0 Answers

Good Looking Grass With Low Batch Count 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