Can not set scales on android build

Hi. As I said, I test that everything works alright before building and indeed it does, but finally when i build it and test it on android, nothing get scaled.

I’m for sure missing something but I really dont know where. I dont know if it has to do with Random.Range, the foreach loop or if it has to do with childs or what but, on android, it doesn’t seem to be working. The piece of code is the following:

public class LevelManager : MonoBehaviour
{
    private float[] tilesScales = {0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1f};

    private void Awake()
    {
        SetScales();
    }

    void SetScales()
    {
        foreach (Transform child in transform)
        {
            if (child.transform.localPosition.y == 0)
            {
                int randomScale = Random.Range(0, tilesScales.Length);
                child.transform.localScale = new Vector3(1, 1, tilesScales[randomScale]);
            }
        }
    }
}

Then, just to try out, I made it so when I tap the screen it calls SetScales() again, but it obviously doesn’t work either.

If you know what should be causing the trouble or have any advice related to mobile devices I would be glad to hear it. Thanks!

So, localPosition.y is a float and checking equality for floats is not a good idea. I would try using Unity - Scripting API: Mathf.Approximately instead

If you use logcat or a runtime console and debug your childs localPosition.y before your if check, it’s possible it’s actually .00000001 or something like that, which means they will never scale.

You are right, I had a similar problem before and it could totally be the thing here. Later I will try to fix it up. Thanks!

Unfortunately, That was not the problem here. I try using
if (Mathf.Approximately(child.transform.localPosition.y, 0))
and also
if (Mathf.RoundToInt(child.transform.localPosition.y) == 0)
but neither way do the work on android, despite working flawlessly inside unity editor.
Any suggest?

Through debugging I found out that (on Android) the void:

void SetScales()
    {
        foreach (Transform child in transform)
        {
            if (Mathf.Approximately(child.transform.localPosition.y, 0))
            {
                int randomScale = Random.Range(0, tilesScales.Length);
                child.transform.localScale = new Vector3(1, 1, tilesScales[randomScale]);
            }
        }
    }

Gets called properly and also the random number gets a correct value who throw the proper number from the array.
The problem is that
child.transform.localScale = new Vector3(1, 1, tilesScales[randomScale]);
is not working, I also try to pass the floats manually but still nothing happens.