Which Joystick Pressed UI Button
So I need to find out which joystick pressed a UI button .
something like..
onClick(Input name){
Debug.Log(name+" clicked" + gameobject.name); // "joystick 1 clicked Button1"
}
Answer by TheYumma · Jun 16, 2017 at 02:51 AM
Will I found a good solution (as far as I know) , attach this script on the Button. We are checking where (position) the event system is selecting with the Button's own position, if they are the same it means we are clicking on the button that has this script.
if someone has any notes or improvements please let me know. I only tested this with one PS4 controller ( I only have 1) .
private void Update()
{
thisPosition = EventSystem.current.currentSelectedGameObject.GetComponent<Transform>().position;
Debug.Log(thisPosition.Equals(myPos));
//For Player1
if (Input.GetButton("PS4_X_P" + playerImages[0].playerNoImg) && (thisPosition == myPos))
{
playerImages[0].GetComponent<Image>().sprite = buttonImage.sprite;
Debug.Log(buttonImage.name);
}
//For Player2
if (Input.GetButton("PS4_X_P" + playerImages[1].playerNoImg) && (thisPosition == myPos))
{
playerImages[1].GetComponent<Image>().sprite = buttonImage.sprite;
Debug.Log(playerImages[0]);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612124215im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
MobileSingleStickControl multitouch not supported. How fix? 0 Answers
Events not working when UI y rotation is not 0 0 Answers
Player character jumping when I wish to only initiate pause - UI Button element. 1 Answer
UI: On pointer down enter detection 0 Answers
Making UI block rays with touch inputs 0 Answers