Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Unity3D apk build having issues that dont show in Unity project

Discussion in 'Android' started by NiallGarganNG, Apr 12, 2024.

  1. NiallGarganNG

    NiallGarganNG

    Joined:
    Mar 9, 2023
    Posts:
    1
    Making a simple button spam game where the user clicks a button and increases a "float score" variable. There is another "float emissions" variable that scales with Time.delta time and also controls a UI Slider. At the end it takes the score and minuses the emissions to give the final score.

    Everything works perfectly in the Unity editor and i tested it with Unity remote on my mobile, however when i build the APK file and freshly install it onto my phone to test, the emissions counter doesn't work, the UI Slider doesnt scale equal to the emissions level and the final score is just 0.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Emissions : MonoBehaviour
    7. {
    8.     public Slider emissions;
    9.     public float currentEmissions;
    10.     private float fillSpeed = 5;
    11.     Timer timer;
    12.     void Start()
    13.     {
    14.         timer = GameObject.Find("Timer").GetComponent<Timer>();
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.         if (timer.isGameActive == true)
    21.         {
    22.             //if game is active keep updating slider
    23.             FillEmissionsOverTime();
    24.             currentEmissions = emissions.value;
    25.         }
    26.     }
    27.  
    28.     void FillEmissionsOverTime()
    29.     {
    30.         //fills the emissions slider bar = fillSpeed and deltaTime
    31.         emissions.value += fillSpeed * Time.deltaTime;
    32.     }
    33.  
    34.     public void DecreaseEmissions()
    35.     {
    36.         //decrease emission slider by 5
    37.         emissions.value = emissions.value - 5;
    38.     }
    39. }
    40.  
    Is Time.deltaTime unstable on Unity Android builds?