Search Unity

OnPointerClick nightmare

Discussion in 'UGUI & TextMesh Pro' started by CWJGregory, Mar 14, 2019.

  1. CWJGregory

    CWJGregory

    Joined:
    Mar 14, 2019
    Posts:
    2
    Hi guys,

    Relatively new to Unity however I'm trying to implement a card match game exercise, however when using the onpointer I'm trying to store the name of the block into an array so I can check if it matches to the other clicked object, however the code isn't storing to the array how I would like it to, the array seems to be individually different to each block. For example if I clicked Block one the log will show null then if I click Block 2 it will still show null. However should I remove the setactive statement and click the same button the array will appear with the correct value in the array. So instead of a global array it is for some reason making a separate array for every block clicked. The array is declared in global so Im really not sure where to go from here.

    Any help would be hugely appreciated

    The onclick code
    public void OnPointerClick(PointerEventData eventData)
    {
    Debug.Log(tiles[0]);
    if (gameObject.name == "Hiddentile")
    {
    string blockname = gameObject.transform.parent.name;
    selectedTile = GameObject.FindGameObjectWithTag(blockname);
    if (tiles[0] != null)
    {
    Debug.Log("blue");
    tiles[1] = selectedTile.GetComponent<Image>().sprite.name;
    Hidtiles[1] = gameObject;
    gameObject.SetActive(false);

    }
    else
    {
    Debug.Log("cheese");
    tiles[0] = selectedTile.GetComponent<Image>().sprite.name;
    Debug.Log(tiles[0]);
    Hidtiles[0] = gameObject;
    gameObject.SetActive(false);


    }
    if (tiles[0] != null && tiles[1] != null)
    {

    {
    txtmatch.text = "A Match";
    tilecount = 0;
    tiles[0] = null;
    tiles[1] = null;
    Hidtiles[0] = null;
    Hidtiles[1] = null;
    }
    else
    {
    txtmatch.text = "No Match";
    forceNum[0] = 0;
    System.Threading.Thread.Sleep(5000);
    Hidtiles[0].SetActive(true);
    Hidtiles[1].SetActive(true);
    tiles[0] = null;
    tiles[1] = null;
    Hidtiles[0] = null;
    Hidtiles[1] = null;

    }
    else
    {

    }
    Debug.Log(tiles[0]);

    }
    }
    /* if (tilecount == 2)
    {
    if()
    }
    else
    {
    if (gameObject.name == "Hiddentile" && gameObject.activeSelf)
    {
    gameObject.SetActive(false);
    }
    }*/

    Thanks