- Home /
Button is Interactable but not interacting
Hi people, Working on an RPG battle system, trying to make something with real-time timers like FF7. I have a player component and an enemy component. When player's timer hits 0, their action button is interactable to set them as active so a target can be chosen from the enemies. A central component then turns all enemy buttons to interactable. The enemy button, however, is not interacting, the box is checked in the editor and i can see it go from low alpha to opaque, but it doesn't click or highlight. My event system is present and it is specifically this button that is not working, i tried remaking it but to no avail, i also tried switching the on click method, but nothing. The console isn't giving me any errors so i come to the community. Thanks in advance.
Here's my code, i don't know if it will help:
public void Activate()
{
// this runs for the player and works fine
Debug.Log(gameObject.name + " is active!");
ActionButton.interactable = false;
Game.SetActiveHero(this);
}
public void SetActiveHero(PlayerBattleControlV2_0 elected)
{
//this works too on the central game manager
activeHero = elected;
foreach (PlayerBattleControlV2_0 hero in heroes)
{
if (hero != activeHero)
{
hero.SwitchSuspend();
}
}
Debug.Log("Enemy Buttons activated");
ToggleEnemyButtons();
}
public void ToggleEnemyButtons()
{
//this toggles all the enemy (only 1 for now) buttons and works
foreach (EnemyBattleControlV2_0 enemy in enemies)
{
enemy.ToggleButton();
}
}
public void ToggleButton()
{
// this is where things go weird, the box is checked but i cant use the button
targetButton.interactable = !targetButton.interactable;
}
public void beTargetted()
{
// this is what is meant to happen when the button is pressed
Debug.Log(gameObject.name + " is targetted");
Game.SetActiveTarget(this);
}
Answer by k234234w · Jul 14, 2019 at 04:30 PM
Does your canvas have a graphics raycaster, without that component on your canvas you wont be able to click on anything. Can you raycast when you click and print off all ui elements you hit, it could be something is invisible that is absorbing the click. Have you tried always having your buttons interactable, that would be a good thing to check to help isolate the problem.
O$$anonymous$$G thank you so much, the neighbouring text i had for the health,cooldown and mana bars all had raycast target checked, unchecking that fixed my problem. Is there any use in that being checked if i'm not going to be clicking them?
If they are not being interacted with they should have raycast target off. I think its actually more performant to turn raycast target off on objects that do not need it.
Answer by marcel0321 · Oct 15, 2019 at 12:30 AM
In the idle state, the button's front plate is not visible. As a finger ... Interactable handles various types of interaction states and events. HoloLens ... This code is working nice. Thanks for sharing...... Official IMO for Windows
Your answer
Follow this Question
Related Questions
How do I close in the distance between the player and object to pick up? 0 Answers
2 canvases working weird with buttons 0 Answers
How I create game for pc and get inventory for an app on my cell phone? 0 Answers
UI mouse click prevent default / stop propagation. (Block mouse events of other scripts) 3 Answers
GearVR Button.One UI interaction 0 Answers