ClientServer/Client/Assets/Scripts/UI/InitializeSelectable.cs

39 lines
1020 B
C#
Raw Normal View History

2025-09-06 17:17:39 +04:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class InitializeSelectable : MonoBehaviour
{
[SerializeField] Selectable initialSelected = null;
void OnEnable()
{
StartCoroutine(WaitThenSelectRoutine());
}
public IEnumerator WaitThenSelectRoutine()
{
yield return null;
if (Player.Instance.GetInputHandler().UsingGamePad)
{
try
{
EventSystem.current.SetSelectedGameObject(null);
EventSystem.current.SetSelectedGameObject(initialSelected.gameObject);
//Debug.Log($"Currently Selected UI Object: {EventSystem.current.currentSelectedGameObject.name}");
}
catch
{
Debug.LogError("I AM NOT ASSIGNED" + gameObject.name);
}
}
else
{
EventSystem.current.SetSelectedGameObject(null);
}
}
}