Search Unity

Question Send Help. My Buttons isn't working in Android build

Discussion in 'UGUI & TextMesh Pro' started by Maple-Senpai, Jul 7, 2020.

  1. Maple-Senpai

    Maple-Senpai

    Joined:
    Oct 2, 2018
    Posts:
    14
    I've been trying to figure out how to fix this for hours and its driving me crazy already.

    So, here how it works.

    1. I have this one panel
    2. Then I generated a bunch of buttons on it, add a grid layout group, content size fitter, Nothing special. Just making sure my buttons will fit in the panel.
    3. Then I add 'Event Triggers' to every single of this buttons. These are BeginDrag, OnPointEnter, and EndDrag. I'm not sure why I used OnPointerEnter instead of the regular Drag event but it also works.
    4. I put a simple Line Renderer that draws in the screen everytime the user starts dragging one of the tiles up to the ending tile. Some sort of a highlighting features because my game is a 'Word Search' game.
    5. All of this works magically good in Unity Editor.

    But android build ended my happiness. The tiles in my grid can't be clicked nor dragged. It just there doing nothing. But I can still click on the UI's outside of the said panel like when tapping the 'Menu' button to return to menu. The panel isn't the only one accepting touches and I can't figure out why.

    Here is the code of the functions I'm adding to the buttons:
    btw, dragHighlight is the BeginDrag
    Code (CSharp):
    1. public void dragHighlight(PointerEventData data, GameObject LetterContainer)
    2.     {
    3.         int r = Random.Range(0, randomFoundColors.Count);
    4.         //=====================LINE RENDERER===========================//
    5.         lr = Instantiate(lineRendererPrefab);
    6.         lr.AddComponent<LineRenderer>();
    7.         lr.GetComponent<LineRenderer>().enabled = true;
    8.         lr.GetComponent<LineRenderer>().positionCount = 2;
    9.         lr.GetComponent<LineRenderer>().material = new Material(Shader.Find("Mobile/Particles/Multiply"));
    10.         lr.GetComponent<LineRenderer>().SetColors(randomFoundColors[r], randomFoundColors[r]);
    11.         GameObject tile = LetterContainer;
    12.         Vector2 tilePos = tile.transform.position;
    13.         startPos = tilePos;
    14.         endPos = tilePos;
    15.         lr.GetComponent<LineRenderer>().SetPosition(1, endPos);
    16.         lr.GetComponent<LineRenderer>().SetPosition(0, startPos);
    17.         lr.GetComponent<LineRenderer>().useWorldSpace = true;
    18.         lr.GetComponent<LineRenderer>().widthCurve = ac;
    19.         lr.GetComponent<LineRenderer>().numCapVertices = 10;
    20.         lr.GetComponent<LineRenderer>().GetComponent<LineRenderer>().sortingOrder = 4;
    21.         //=====================END OF LINE RENDERER===========================//
    22.         string tag = LetterContainer.tag;
    23.         storeDiagonalID = tag;
    24.         tag = tag.Substring(0, tag.Length - 1);
    25.         Debug.Log("Tag is: " + tag);
    26.         if (dragging == false)
    27.         {
    28.             letterSwipeSound();
    29.             LetterContainer.GetComponent<Button>().interactable = false;
    30.             for (int x = 0; x < maxVerticalLine; x++)
    31.             {
    32.                 for (int y = 0; y < maxHorizontalLine; y++)
    33.                 {
    34.                     if (gridSize[x, y] == LetterContainer)
    35.                     {
    36.                         firstLetter_x = x;
    37.                         firstLetter_y = y;
    38.                         break;
    39.                     }
    40.                     else
    41.                         continue;
    42.                 }
    43.             }
    44.             dragging = true;
    45.         }
    46.     }
    47.  
    48.     public void pointerEnter(PointerEventData data, GameObject LetterContainer)
    49.     {
    50.         wordFormed = "";
    51.         if (dragging == true)
    52.         {
    53.             //==========================LINE RENDERER=======================================//
    54.             GameObject tile = LetterContainer;
    55.             Vector3 tilePos = tile.transform.position;
    56.             endPos = tilePos;
    57.             lr.GetComponent<LineRenderer>().SetPosition(1, endPos);
    58.             //=========================END OF LINE RENDERER================================//
    59.             letterSwipeSound();
    60.             for (int x = 0; x < maxVerticalLine; x++)
    61.             {
    62.                 for (int y = 0; y < maxHorizontalLine; y++)
    63.                 {
    64.                     if (gridSize[x, y] == LetterContainer)
    65.                     {
    66.                         lastLetter_x = x;
    67.                         lastLetter_y = y;
    68.                         break;
    69.                     }
    70.                     else
    71.                         continue;
    72.                 }
    73.             }
    74.             if(firstLetter_x == lastLetter_x)
    75.             {
    76.                 if(firstLetter_y < lastLetter_y)
    77.                 {
    78.                     for (int y = firstLetter_y; y <= lastLetter_y; y++)
    79.                     {
    80.                         string selectedLetter = gridSize[firstLetter_x, y].GetComponentInChildren<TMPro.TMP_Text>().text;
    81.                         wordFormed = wordFormed + selectedLetter;
    82.                     }
    83.                 }
    84.                 else
    85.                     for (int y = firstLetter_y; y >= lastLetter_y; y--)
    86.                     {
    87.                         string selectedLetter = gridSize[firstLetter_x, y].GetComponentInChildren<TMPro.TMP_Text>().text;
    88.                         wordFormed = wordFormed + selectedLetter;
    89.                     }
    90.  
    91.             }
    92.             if(firstLetter_y == lastLetter_y)
    93.             {
    94.                 if(firstLetter_x < lastLetter_x)
    95.                 {
    96.                     for (int x = firstLetter_x; x <= lastLetter_x; x++)
    97.                     {
    98.                         string selectedLetter = gridSize[x, firstLetter_y].GetComponentInChildren<TMPro.TMP_Text>().text;
    99.                         wordFormed = wordFormed + selectedLetter;
    100.                     }
    101.                 }
    102.                 else
    103.                 {
    104.                     for (int x = firstLetter_x; x >= lastLetter_x; x--)
    105.                     {
    106.                         string selectedLetter = gridSize[x, firstLetter_y].GetComponentInChildren<TMPro.TMP_Text>().text;
    107.                         wordFormed = wordFormed + selectedLetter;
    108.                     }
    109.                 }
    110.             }
    111.             if(firstLetter_x != lastLetter_x)
    112.             {
    113.                 if(firstLetter_y != lastLetter_y)
    114.                 {
    115.                     if(firstLetter_x < lastLetter_x)
    116.                     {
    117.                         int y = firstLetter_y;
    118.                         for (int x = firstLetter_x; x <= lastLetter_x; x++)
    119.                         {
    120.                             string selectedLetter = gridSize[x, y].GetComponentInChildren<TMPro.TMP_Text>().text;
    121.                             wordFormed = wordFormed + selectedLetter;
    122.                             y++;
    123.                         }
    124.                     }
    125.                     else
    126.                     {
    127.                         int y = firstLetter_y;
    128.                         for (int x = firstLetter_x; x >= lastLetter_x; x--)
    129.                         {
    130.                             string selectedLetter = gridSize[x, y].GetComponentInChildren<TMPro.TMP_Text>().text;
    131.                             wordFormed = wordFormed + selectedLetter;
    132.                             y--;
    133.                         }
    134.                     }
    135.                 }
    136.             }
    137.             Debug.Log("Formed word is: " + wordFormed);
    138.         }
    139.     }
    140.  
    141.     public void dragEnd(PointerEventData data, GameObject LetterContainer)
    142.     {
    143.         int r = Random.Range(0, randomFoundColors.Count);
    144.         var objects = GameObject.FindGameObjectsWithTag("words");
    145.         var objectCount = objects.Length;
    146.         foreach (var obj in objects)
    147.         {
    148.             string reversed = ReverseString(wordFormed);
    149.             if (obj.GetComponent<TMPro.TMP_Text>().text.Trim().Equals(wordFormed) || obj.GetComponent<TMPro.TMP_Text>().text.Trim().Equals(reversed))
    150.             {
    151.                 wordFoundSound();
    152.                 unableToFindWord = false;
    153.                 obj.GetComponent<TMPro.TMP_Text>().fontStyle = TMPro.FontStyles.Strikethrough;
    154.                 wordFormed = "";
    155.                 var letters = GameObject.FindGameObjectsWithTag("letters");
    156.                 var lettersCount = objects.Length;
    157.                 foreach (var let in letters)
    158.                 {
    159.                     if (let.GetComponent<Image>().color == green)
    160.                     {
    161.                         let.GetComponent<Image>().color = randomFoundColors[r];
    162.                         let.tag = "letters(found)";
    163.                     }
    164.                 }
    165.                 var letters_diagonal = GameObject.FindGameObjectsWithTag(storeDiagonalID);
    166.                 var lettersCount_diagonal = objects.Length;
    167.                 foreach (var let in letters_diagonal)
    168.                 {
    169.                     if (let.GetComponent<Image>().color == green)
    170.                     {
    171.                         let.GetComponent<Image>().color = randomFoundColors[r];
    172.                     }
    173.                 }
    174.                 wordInStage--;
    175.                 if (wordInStage == 0)
    176.                 {
    177.                     int medals = PlayerPrefs.GetInt("Medals") + 1;
    178.                     PlayerPrefs.SetInt("Medals", medals);
    179.                     PlayerPrefs.Save();
    180.                     resultScreen.SetActive(true);
    181.                     isGameComplete = true;
    182.                 }
    183.                 break;
    184.             }
    185.             else
    186.                 unableToFindWord = true;
    187.         }
    188.         if(unableToFindWord == true)
    189.         {
    190.             Destroy(lr);
    191.             unableToFindWord = false;
    192.         }
    193.         foreach (GameObject _let in GameObject.FindObjectsOfType<GameObject>())
    194.         {
    195.             if (_let.name == "Letter(Clone)")
    196.             {
    197.                 if (_let.GetComponent<Image>().color == green)
    198.                 {
    199.                     _let.GetComponent<Image>().color = Color.white;
    200.                 }
    201.             }
    202.  
    203.         }
    204.         wordFormed = "";
    205.         dragging = false;
    206.         diagonalDragging = false;
    207.     }
    And I tried drawing a line renderer outside of the panel and it works so I think its not Line Renderer's fault.
    I also tried messing around with the Panel's raycast, graphics raycasters, sorting order, etc thinking that something might be blocking the taps. Still no luck.


    Any help? :(
     
  2. Maple-Senpai

    Maple-Senpai

    Joined:
    Oct 2, 2018
    Posts:
    14
    I finally figured out the problem. I'm such a noob :p
    In case, somebody is also having the same problem... Turns out the shader I'm using for the Line Renderer in Line 9
    wasn't included in the build.
    To fix it just to to project settings > graphics > always include shaders > change the size if the shader you are using isn't included > select your shader.