#this is in managerUi cs but when i
1 messages · Page 1 of 1 (latest)
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class managerUi : MonoBehaviour
{
public managerWeaponChange mngrWeaponChange;
// Start is called before the first frame update
void Start()
{
mngrWeaponChange = GameObject.FindGameObjectWithTag("Player").GetComponent<managerWeaponChange>();
}
public void ButtonWeaponChange()
{
Debug.Log(EventSystem.current.currentSelectedGameObject);
GameObject tempBtn = EventSystem.current.currentSelectedGameObject;
int tempBtnIndex = tempBtn.transform.GetSiblingIndex();
mngrWeaponChange.ChangeWeapon(tempBtnIndex);
//Debug.Log (tempBtn + ":" + tempBtnIndex);
}
}
this is manageUi.cs
this is KeyPress.cs
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class KeyPress : MonoBehaviour
{
public KeyCode _Key;
public Button managerUi;
void Awake()
{
managerUi = GetComponent<Button>();
}
void Update()
{
if(Input.GetKeyDown(_Key))
{
FadeToColor(managerUi.colors.pressedColor);
managerUi.onClick.Invoke();
}
else if(Input.GetKeyUp(_Key))
{
FadeToColor(managerUi.colors.normalColor);
}
}
void FadeToColor(Color color)
{
Graphic graphic = GetComponent<Graphic>();
graphic.CrossFadeColor(color, managerUi.colors.fadeDuration, true, true);
}
}```
screenshot the event system
click the replace button
replace button?
yes
replace with the inputsystem?
yes
the one under the big red error icon
now see if it works
the button press works, but the player's hand is empty
GameObject tempBtn = EventSystem.current.currentSelectedGameObject; is null, fix that
how to do that?