Is there a way to toggle the raycast target on the Dialogue System UI elements? Primarily for Images and Text UI?
The reason that I want this is I have a game that uses both the mouse to interact with various things, and WASD or controller movement controls, but, when the mouse is hovering over UI with raycast target elements, it will interfere with the movement controls. I.E. The Player cannot move while the mouse is over UI that has raycast targets, or, if the Player is already moving, they will get stuck moving and cannot stop.
Therefore, I would like to be able to choose when the raycast target is happening for Dialogue images and text. If for instance, the Player walks through a trigger box and I have a dialogue come up with only 1 option, this is basically an exposition scenario where I would set 'SetTimeOut(4)' or something to automatically cycle through the dialogue, and the Player doesn't really need to select an option, so the raycast of the UI isn't needed. But if there was a situation where the Player response choice was important, than I'd turn the raycasts back on.
Since the dialogue canvas appears to get duplicated at Start() I was having trouble setting direct references to the panel game objects, so I tried to set up a tag system and do something like this:
Code: Select all
public void DialogueRaycastOff()
{
GameObject[] DialogueImagePanels = GameObject.FindGameObjectsWithTag("DialogueImagePanel");
foreach (GameObject Panel in DialogueImagePanels)
{
Panel.GetComponent<Image>().raycastTarget = false;
Debug.Log("Dialogue Image Panels " + Panel.name);
}
GameObject[] DialogueTextPanels = GameObject.FindGameObjectsWithTag("DialogueTextPanel");
foreach (GameObject Panel in DialogueTextPanels)
{
Panel.GetComponent<Text>().raycastTarget = false;
Debug.Log("Dialogue Text Panels " + Panel.name);
}
}
public void DialogueRaycastOn()
{
GameObject[] DialogueImagePanels = GameObject.FindGameObjectsWithTag("DialogueImagePanel");
foreach (GameObject Panel in DialogueImagePanels)
{
Panel.GetComponent<Image>().raycastTarget = true;
}
GameObject[] DialogueTextPanels = GameObject.FindGameObjectsWithTag("DialogueTextPanel");
foreach (GameObject Panel in DialogueTextPanels)
{
Panel.GetComponent<Text>().raycastTarget = true;
}
}
Is there a simpler approach or any kind of built in way to do this?
Thanks.