❔ Click event not working in Unity

I have created two buttons, one for previous and one for next. Each one has a method Previous() or Next() attached to it's OnClick event. For Some reason Previous() gets invoked but Next() does not. I did the same thing for both buttons. I put Debug.Log("previous was called") and Debug.Log("next was called") to make sure and i never see "next was called" when clicking. What could be the issue for this? Something I thought of is that maybe there is something in front of the Next button that doesn't let me click the button but I didn't place anything other than the button there.
5 Replies
Florian Voß
Florian VoßOP2y ago
public class CharacterClassSelector : MonoBehaviour
{
public CharacterClassDb _context;
public TextMeshProUGUI className;
public SpriteRenderer classRenderer;
public int currentIndex = 0;
void Start()
{
UpdateSprite(currentIndex);
}
public void Next(){
Debug.Log("Next was called");
if(currentIndex >= _context.Count-1){
currentIndex = 0;
}else{
currentIndex++;
}
UpdateSprite(currentIndex);
}
public void Previous(){
Debug.Log("Prev was called");
if(currentIndex <= 0) currentIndex = _context.Count;
currentIndex--;
UpdateSprite(currentIndex);
}
public void UpdateSprite(int index){
CharacterClass selectedClass = _context.GetCharacter(index);
classRenderer.sprite = selectedClass.sprite;
}
}
public class CharacterClassSelector : MonoBehaviour
{
public CharacterClassDb _context;
public TextMeshProUGUI className;
public SpriteRenderer classRenderer;
public int currentIndex = 0;
void Start()
{
UpdateSprite(currentIndex);
}
public void Next(){
Debug.Log("Next was called");
if(currentIndex >= _context.Count-1){
currentIndex = 0;
}else{
currentIndex++;
}
UpdateSprite(currentIndex);
}
public void Previous(){
Debug.Log("Prev was called");
if(currentIndex <= 0) currentIndex = _context.Count;
currentIndex--;
UpdateSprite(currentIndex);
}
public void UpdateSprite(int index){
CharacterClass selectedClass = _context.GetCharacter(index);
classRenderer.sprite = selectedClass.sprite;
}
}
Florian Voß
Florian VoßOP2y ago
Florian Voß
Florian VoßOP2y ago
Florian Voß
Florian VoßOP2y ago
turns out only one of the two events was working because I had created the Next button by rotating the Previous button. After unchecking the box "ignore reversed graphics" in Raycaster or smth like that it worked. If anyone could explain, I don't really understand this checkbox
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server