S
S
sa2rday2022-04-16 17:19:04
Unity
sa2rday, 2022-04-16 17:19:04

The object does not respond to clicking. How to decide?

I need to make ui elements active when clicking on an object. I implemented swipes through the Event System.
There is Physics Raycast 2d on the camera, I tried to put just Physics Raycast, but it does not work with 2d.

Code inside
using System.Diagnostics;
using System.Reflection;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class CHELcommunications : MonoBehaviour, IPointerClickHandler
{
    public GameObject HealthCheck;
    public GameObject GYMCheck;
    public GameObject EatCheck;
    public GameObject SleepCheck;

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        //изменяет положение челикса с камерой
        if(ChangeRoom.Place == 3){
            transform.position = new Vector3(-16.6f,1.3f,-4.2f);
            Close_ui_switch_room();
        }
        if(ChangeRoom.Place == 2){
            transform.position = new Vector3(-8.0f,0.7f,-3.79f);
            Close_ui_switch_room();
        }
        if(ChangeRoom.Place == 1){
            transform.position = new Vector3(4.5f,1.4f,-4.0f);
            Close_ui_switch_room();
        }
        if(ChangeRoom.Place == 0){
            transform.position = new Vector3(0.0f,0.7f,-4.1f);
            Close_ui_switch_room();
        }
    }
    //открываю меню 
    public void OpenUi(float Num){
        if (Num == 0){
            GYMCheck.SetActive(false);
            SleepCheck.SetActive(false);
            EatCheck.SetActive(true);
        }
        if (Num == 1){
            EatCheck.SetActive(false);
            SleepCheck.SetActive(true);
        }
        if (Num == 2){
            EatCheck.SetActive(false);
            GYMCheck.SetActive(true);
            HealthCheck.SetActive(false);
        }
        if (Num == 3){
            HealthCheck.SetActive(true);
            GYMCheck.SetActive(false);
        }
    }
    //закрывает все окна при переходе на другой экран
    public void Close_ui_switch_room(){
        GYMCheck.SetActive(false);
        SleepCheck.SetActive(false);
        EatCheck.SetActive(false);
        HealthCheck.SetActive(false);
    }
    public void OnPointerClick(PointerEventData eventData)
    {
        OpenUi(ChangeRoom.Place);
    }
}


ChangeRoom.Place is a static variable with a number inside


Screenshots inside
625ad041edcb2224125851.png
625ad04aca868923903894.png
625ad051dc696157110076.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kerim Rezai Shirazi, 2022-04-16
@sa2rday

if(ChangeRoom.Place == 3){
            transform.position = new Vector3(-16.6f,1.3f,-4.2f);
            Close_ui_switch_room();
        }
        if(ChangeRoom.Place == 2){
            transform.position = new Vector3(-8.0f,0.7f,-3.79f);
            Close_ui_switch_room();
        }
        if(ChangeRoom.Place == 1){
            transform.position = new Vector3(4.5f,1.4f,-4.0f);
            Close_ui_switch_room();
        }
        if(ChangeRoom.Place == 0){
            transform.position = new Vector3(0.0f,0.7f,-4.1f);
            Close_ui_switch_room();
        }
this part when try to put in fixedupdate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question