1 (edited by 0massimo0 2023-11-09 02:05:35)

Topic: Problem Scrolling with Gamepad

Video my game https://youtu.be/IKXaXPmha-4
Video tutorial https://www.youtube.com/watch?v=WhwHBqjWelk

UFE STANDAR 2.5.3

I am not a programmer, I followed a video tutorial to create what I showed in the video.
The problem is that it works with the mouse but not with the pad. how can i solve it?
What piece of code needs to be added to make it work even when I press the gamepad attack button?

-------------------------------------------------------------------------------------------------------------------------------------

FIRST CODE

using UnityEngine;
using UnityEngine.EventSystem;


public class ScrollButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public bool isDown = false;

public void OnPointerDown(PointerEventData eventData)
{
isDown = true;
}
public void OnPointerUp(PointerEventData eventData)
{
isDown = false;
}
}

----------------------------------------------------------------------------------------------------------------------------------------

SECOND CODE

using UnityEngine.UI;

public class scrollViewSystem : MonoBehaviour
{
private ScrollRect _scrollRect;

[Serializefield] private ScroolButton _leftButton;
[Serializefield] private ScroolButton _rightButton;
[Serializefield] private ScroolButton _bottomButton;
[Serializefield] private ScroolButton _topButton;

[Serializefield] private float scroolSpeed = 0.01f;
 
void Start()
{
_scrollRect = GetComponet<ScrollRect>();
}
void Update()
{
if(_leftButton != null)
{
if(_leftButton.isDown)
{
ScroolLeft();
}
}
if(_rightButton != null)
{
if(_rightButton.isDown)
{
ScroolRight();
}
}
if(_bottomButton != null)
{
if(_bottomButton.isDown)
{
ScroolBottom();
}
}
if(_topButton != null)
{
if(_topButton.isDown)
{
ScroolTop();
}
}
}
private void ScrollLeft()
{
if(_scrollRect != null)
{
if(_scrollRect.horizontalNormalizePosition >= 0f )
{
_scrollRect.horizontalNormalizePosition -= scrollSpeed;
}
}
}

private void ScrollRight()
{
if(_scrollRect != null)
{
if(_scrollRect.horizontalNormalizePosition <= 1f )
{
_scrollRect.horizontalNormalizePosition += scrollSpeed;
}
}
}

private void ScrollTop()
{
if(_scrollRect != null)
{
if(_scrollRect.verticalNormalizePosition <= 1f )
{
_scrollRect.verticalNormalizePosition += scrollSpeed;
}
}
}

private void ScrollBottom()
{
if(_scrollRect != null)
{
if(_scrollRect.verticalNormalizePosition >= 0f )
{
_scrollRect.verticalNormalizePosition -= scrollSpeed;
}
}
}
}

Share

Thumbs up Thumbs down

Re: Problem Scrolling with Gamepad

You would have to code your own system for scrolling a scroll rect with a gamepad.
I've managed to do it, but it's a bit complicated.
I have some scripts to do it in my github, but I may just end up writing a tutorial for this.

Share

Thumbs up +1 Thumbs down