Как с помощью Raycast определить tag UI обьекта и взаимодействовать с ним?

Сделал для своей игры кейсы но возникла проблема : я не знаю как с помощью Raycast определить tag UI обьекта и взаимодействовать с ним. Тоесть когда Raycast касался UI обьекта он определял его tag и взависимости от тэга на карте появлялся обьект (setActive(true)).Код:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class CaseScript : MonoBehaviour {

    public bool openCase = false;
    public GameObject[] prefabs;
    public GameObject sp;
    public float scrollSpeed = -20f;
    private float velocity = 3f;
    public WSprites[] ws;
    public Image[] prefabsimages;
    public Image finalDrop;
    public GameObject dropPan;
    public GameObject Opened;
    public GameObject Case;
    private int currentCase;
    private bool wasPlayedDrop = false;
    private string Index;
    public GameObject Aim;

    public GameObject LibCs;
    public int price;
    public GameObject Player;
    public GameObject DropBl;
    public GameObject DropBlue;
    public GameObject DropPurple;
    public GameObject DropRed;
    public GameObject DropPink;
    public GameObject DropGrey;

    void Start()
    {

    }

    void Update()
    {
        if (openCase)
        {
            scrollSpeed = Mathf.MoveTowards(scrollSpeed, 0, velocity * Time.deltaTime);
            RaycastHit2D hit = Physics2D.Raycast(Vector2.down, Vector2.up);
            if (hit.collider != null)
                RaycastHit hit;
            {

            }
            {
                if (scrollSpeed == 0)
                    
                {
                    dropPan.SetActive(true);
                    finalDrop.sprite = hit.collider.gameObject.GetComponent<Image>().sprite;
                    if (hit.collider.tag == "RED")
                    {
                        DropRed.SetActive(true);
                    }

                    if (Physics.Raycast(_ray, out hit) && hit.gameObject.tag == "PINK")
                    {
                        DropPink.SetActive(true);
                    }

                    if (Physics.Raycast(_ray, out hit) && hit.gameObject.tag == "PURPLE")
                    {
                        DropPurple.SetActive(true);
                    }

                    if (Physics.Raycast(_ray, out hit) && hit.gameObject.tag == "BLUE")
                    {
                        DropBlue.SetActive(true);
                    }

                    if (Physics.Raycast(_ray, out hit) && hit.gameObject.tag == "BL")
                    {
                        DropBl.SetActive(true);
                    }

                    if (Physics.Raycast(_ray, out hit) && hit.gameObject.tag == "GRAY")
                    {
                        DropGrey.SetActive(true);

                    }



                }
                else if (scrollSpeed == 0)
                {
                    scrollSpeed = Mathf.MoveTowards(scrollSpeed, -5f, velocity * Time.deltaTime);
                }
            }
        }
    }
    public void caseBttn(int caseInt)
    {
        if (Player.GetComponent<MoneyIvent>().Money >= price)
        {
            Player.GetComponent<MoneyIvent>().Money -= price;
            LibCs.GetComponent<Inventoty>().Items -= 1;

            openCase = true;
            Case.SetActive(false);
            Opened.SetActive(true);
            gameObject.SetActive(true);
            simulateCases();
            velocity = Random.Range(6, 11f);
        }
        else if (scrollSpeed == 0)
        {
            scrollSpeed = Mathf.MoveTowards(scrollSpeed, -5f, velocity * Time.deltaTime);
        }
        else
        {


        }

    }

    void simulateCases()
    {
        for (int a = 0; a < 30; a++)
        {
            int rand = Random.Range(0, 1000);
            int randWeapon = 0;
            if (rand <= 500)
            {
                randWeapon = 0;
                prefabsimages[randWeapon].sprite = ws[currentCase].GrayW[Random.Range(0, ws[currentCase].GrayW.Length)];
            }
            else if (rand > 700 && rand <= 830)
            {
                randWeapon = 1;
                prefabsimages[randWeapon].sprite = ws[currentCase].blueW[Random.Range(0, ws[currentCase].blueW.Length)];
            }
            else if (rand > 830 && rand <= 860)
            {
                randWeapon = 2;
                prefabsimages[randWeapon].sprite = ws[currentCase].purpleW[Random.Range(0, ws[currentCase].purpleW.Length)];
            }
            else if (rand > 930 && rand <= 990)
            {
                randWeapon = 3;
                prefabsimages[randWeapon].sprite = ws[currentCase].redW[Random.Range(0, ws[currentCase].redW.Length)];
            }
            else if (rand > 990)
            {
                randWeapon = 4;
                prefabsimages[randWeapon].sprite = ws[currentCase].knife[Random.Range(0, ws[currentCase].knife.Length)];
            }
            else if (rand > 860 && rand <= 930)
            {
                randWeapon = 5;
                prefabsimages[randWeapon].sprite = ws[currentCase].pinkW[Random.Range(0, ws[currentCase].pinkW.Length)];
            }
            else if (rand > 500 && rand <= 700)
            {
                randWeapon = 6;
                prefabsimages[randWeapon].sprite = ws[currentCase].BlW[Random.Range(0, ws[currentCase].BlW.Length)];
            }
            GameObject obj = Instantiate(prefabs[randWeapon], new Vector2(0, 0), Quaternion.identity) as GameObject;
            obj.transform.SetParent(sp.transform);
            obj.transform.localScale = new Vector2(1, 1);
        }
    }
}

P.s Ответ поподронее а лучше скрипт)))


Ответы (0 шт):