Hi, I have my project so I don’t have the logic to call:
- public bool HandleRaycast(PlayerController callingController)
- GetCursorType()
So I created my script, and everything works, except one thing: I can’t click on the Choice buttons with the left-click mouse. But I can click on the next or close icon.
If I set, it in the script, right-click mouse it is working. But I need it for the left click as well. I thought it is some problem with the player attack, yes attack is triggered by left click mouse. So I disabled the attack. Did not work. I have tried to freeze everything by WindowFreezer script, same problem.
The only thing which is helping is when a player goes away and then I can hit the choice button. But this is nonsense - in real games, players can’t move when dialogue is triggered.
Can you help me, please? Not sure what is going on.
Here are the scripts:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RPG.Dialogue
{
public class AIConversant : MonoBehaviour
{
private bool playerInRange = false;
private PlayerConversant playerConversant = null;
[SerializeField] Dialogue dialogue;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
playerInRange = true;
playerConversant = other.GetComponent<PlayerConversant>();
Debug.Log("Player entered range");
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
playerInRange = false;
playerConversant = null;
Debug.Log("Player exited range");
}
}
private void Update()
{
if (playerInRange && Input.GetButtonDown("Fire1")) // GetMouseButtonDown(0) -> WON'T WORK
{
Debug.Log("Clicked Ally");
playerConversant.StartDialogue(dialogue);
}
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
namespace RPG.Dialogue
{
public class PlayerConversant : MonoBehaviour
{
Dialogue currentDialogue;
DialogueNode currentNode = null;
bool isChoosing = false;
// public listener
public event Action onConversationUpdated;
public void StartDialogue(Dialogue newDialogue)
{
currentDialogue = newDialogue;
currentNode = currentDialogue.GetRootNode();
onConversationUpdated();
}
public void Quit()
{
currentDialogue = null;
currentNode = null;
isChoosing = false;
onConversationUpdated();
}
public bool IsActive()
{
return currentDialogue != null;
}
public bool IsChoosing()
{
return isChoosing;
}
public string GetText()
{
if (currentNode == null)
{
return "";
}
return currentNode.GetText();
}
public IEnumerable<DialogueNode> GetChoices()
{
return currentDialogue.GetPlayerChildren(currentNode);
}
public void SelectChoice(DialogueNode chosenNode)
{
currentNode = chosenNode;
isChoosing = false;
Next();
}
public void Next()
{
int numPlayerResponses = currentDialogue.GetPlayerChildren(currentNode).Count();
if (numPlayerResponses > 0)
{
isChoosing = true;
onConversationUpdated();
return;
}
DialogueNode[] children = currentDialogue.GetAIChildren(currentNode).ToArray();
int randomIndex = UnityEngine.Random.Range(0, children.Count());
currentNode = children[randomIndex];
onConversationUpdated();
}
public bool HasNext()
{
return currentDialogue.GetAllChildren(currentNode).Count() > 0;
}
}
}