0

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.

  • Did you make sure to select Android as the targeted platform ? – DevAm00 Jul 06 '23 at 06:15
  • @DevAm00 if I understand correctly the problem is not building for android and running on android .. the issue seems rather that when running on android something doesn't behave s expected – derHugo Jul 06 '23 at 06:42
  • Within Unity in the GameView do you use the same screen resolution of your phone? Maybe the UI is just configured strange so the layout is off? – derHugo Jul 06 '23 at 06:48
  • Yeah I targeted it to Android, and the issue isn't the build. Also yeah same screen resolution, there is no problem with layout or UI but that gameobjects simply does not exist that should have been 40 in number, there is only 1 gameobject when there should have been 40 and that too only on one player's side, it's a two player game. – TFO Society Jul 06 '23 at 09:06
  • The issue I guess is with specifically the Waiter(), it feels as if only gameobject tam is spawned while tam2 isn't spawned at all and on top of that only 1 tam when there should have been 40 tam and tam2 – TFO Society Jul 06 '23 at 09:09

0 Answers0