Script working fine in Unity remote 5 but not when built to android

36 Views Asked by At

The script is working just fine in editor and remote 5 but only spawns 1 tile when built to android, however it spawns 40 tiles on both sides of the screen in editor and remote 5, while it spawns only 1 tile on 1 side in android and then does nothing, the script is attached to the maincamera. The script is for a colour tile matching game.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Matchager : MonoBehaviour
{
    SpriteRenderer spr1;
    SpriteRenderer spr2;
    [SerializeField] Sprite[] sprotes;
    [SerializeField] GameObject[] Endres;
    [SerializeField] GameObject[] All;
    [SerializeField] GameObject Fold1;
    [SerializeField] GameObject Fold2;
    [SerializeField] GameObject note1;
    [SerializeField] GameObject note2;
    [SerializeField] GameObject note3;
    public static GameObject currentnote;
    public static GameObject currentnote2;
    public static bool notpressable;
    public static bool notpressable2;
    public static bool corunner;
    public static bool corunner2;
    bool runnow;

    private void Start()
    {
        spr1 = Endres[5].GetComponent<SpriteRenderer>();
        spr2 = Endres[6].GetComponent<SpriteRenderer>();
        Invoke("Waiter", 2f);
    }

    private void Update()
    {
        if (Fold1.transform.childCount == 0 && runnow)
            bottomwin();
        else if (Fold2.transform.childCount == 0 && runnow)
            topwin();
    }

    private GameObject GetRandomNote()
    {
        int randomIndex = Random.Range(0, 3);

        switch (randomIndex)
        {
            case 0:
                return note1;
            case 1:
                return note2;
            case 2:
                return note3;
            default:
                return null;
        }
    }

    void Waiter()
    {
        for (int i = 0; i < 40; i++)
        {
            Vector3Int tilePosition = new Vector3Int(0 + (i * 5), -2, 0);
            GameObject tam = Instantiate(GetRandomNote(), Fold1.transform);
            GameObject tam2 = Instantiate(tam, Fold2.transform);
            tam.transform.position = tilePosition;
            tam2.transform.position = -tilePosition;
            if (tam.GetComponent<Matchotes>().Uni == 1)
                tam2.GetComponent<Matchotes>().Uni = 4;
            else if (tam.GetComponent<Matchotes>().Uni == 2)
                tam2.GetComponent<Matchotes>().Uni = 5;
            else if (tam.GetComponent<Matchotes>().Uni == 3)
                tam2.GetComponent<Matchotes>().Uni = 6;
        }
        runnow = true;
    }

    void topwin()
    {
        Fold1.SetActive(false);
        Fold2.SetActive(false);
        foreach (GameObject game in All)
            game.SetActive(false);
        Endres[0].SetActive(true);
        Endres[1].SetActive(true);
        Endres[4].SetActive(true);
        Endres[7].SetActive(true);
        Endres[8].SetActive(true);
        RectTransform rect = Endres[2].GetComponent<RectTransform>();
        RectTransform rect2 = Endres[3].GetComponent<RectTransform>();
        rect.anchoredPosition = new Vector2(rect.anchoredPosition.x, 100);
        rect.localRotation = Quaternion.Euler(rect.localRotation.x, rect.localRotation.x, 180);
        rect2.anchoredPosition = new Vector2(rect.anchoredPosition.x, -100);
        spr1.sprite = sprotes[0];
        spr2.sprite = sprotes[1];
    }

    void bottomwin()
    {
        Fold1.SetActive(false);
        Fold2.SetActive(false);
        foreach (GameObject game in All)
            game.SetActive(false);
        Endres[0].SetActive(true);
        Endres[1].SetActive(true);
        Endres[4].SetActive(true);
        Endres[7].SetActive(true);
        Endres[8].SetActive(true);
        RectTransform rect = Endres[2].GetComponent<RectTransform>();
        RectTransform rect2 = Endres[3].GetComponent<RectTransform>();
        rect.anchoredPosition = new Vector2(rect.anchoredPosition.x, -100);
        rect2.localRotation = Quaternion.Euler(rect.localRotation.x, rect.localRotation.x, 180);
        rect2.anchoredPosition = new Vector2(rect.anchoredPosition.x, 100);
        spr1.sprite = sprotes[2];
        spr2.sprite = sprotes[3];
    }
}

Make a new scene to test it but still didnt work, also moved the script from camera to a new gameobject with nothing except the Matchager script.

0

There are 0 best solutions below