- Home /
Button is not being clicked.
Hi I have been working on a project for the last month or so and I ended up screwing it up badly last night (deleting ground and other stuff) and now once I had it back up and running my NPC's are not working (which is odd because they were not affected). They use Unity's new UI and the way it works is that when you press the button (the dialogue box) it iterates a variable in a script I named count and the dialogue boxes text is the counts text. But count will not iterate. I believe this is because of my lacking of knowledge with Event Systems. It is quite likely one had been deleted and I am just unsure where to place it this time but my buttons appear to be non interactable. I had found a spot for my Event System for when my mouse hovers over it, it appears to light up but the clicking does not work. I feel as though in that position the Event System takes control of my button and it no longer works. So in conclusion I have an NPC with a button that cannot be pressed. Any help is much appreciated.
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class chattingScript : $$anonymous$$onoBehaviour
{ public GameObject dialogueBox; public GameObject chatBubble;
public GameObject storeWindow;
public Text dialogueText;
private string targetDialogue;
public static bool isChatting = false;
public string[] dialogue = new string[5];
public int maxDialogue;
public int count = 0;
private int numSentences;
private bool isFinished;
public enum NPCType{Dialogue, Vendor};
public NPCType myType;
private char _nextChar;
private int _nextCharIndice;
public static bool isInteracting;
void Start()
{
dialogueBox.SetActive(false);
chatBubble.SetActive(false);
count = 0;
storeWindow.SetActive(false);
targetDialogue = dialogue[count];
dialogueText.text = null;
isFinished = false;
// StartCoroutine(DisplayText(5f));
}
void OnTriggerEnter(Collider col)
{
dialogueBox.SetActive(true);
isChatting = true;
//InvokeRepeating("TextTyper", 0.5f, 0.5f);
}
void OnTriggerExit(Collider col)
{
dialogueBox.SetActive(false);
storeWindow.SetActive(false);
count = 0;
isChatting = false;
}
void Update()
{
dialogueText.text = dialogue[count];
if (count == 1 && isChatting != true)
{
isChatting = true;
}
else if (count == 0)
{
isChatting = false;
}
else if (count >= maxDialogue)
{
if (myType == NPCType.Vendor)
{
storeWindow.SetActive(true);
dialogueBox.SetActive(false);
chatBubble.SetActive(false);
}
else
isChatting = false;
}
else if(count > maxDialogue)
{
storeWindow.SetActive(true);
dialogueBox.SetActive(false);
chatBubble.SetActive(false);
}
if (isChatting == true || inventoryScript.isOpen == true || trickortreatScript.isTricking == true)
{
isInteracting = true;
}
else
{
isInteracting = false;
}
}
/*
IEnumerator DisplayText(float delayTime)
{
delayTime = 10f;
for (int i = 0; i < targetDialogue.Length; i++)
{
int initialCount = count;
Debug.Log(dialogueText.text);
Debug.LogError(count);
if (dialogueText.text.Length != targetDialogue.Length)
{
char _nextChar = targetDialogue[i];
dialogueText.text += _nextChar;
for (int j = 0; dialogueText.text.Length != targetDialogue.Length; j++)
{
yield return new WaitForSeconds(10f);
if (j == dialogueText.text.Length)
{
break;
}
}
}
else
{
isFinished = true;
}
}
}
*/
That is for displaying the right text. Currently the way it works is that is has a button that has the OnClick thing having it so it calls OnClick in my script which iterates count.
Sorry it cut off a piece
This part is the part that is called when the button is clicked
public void OnClick()
{
Debug.Log("I was clicked");
count += 1;
}
Answer by unimechanic · Oct 08, 2014 at 02:56 PM
They use Unity's new UI
You can also ask in the Beta group where our developers can investigate the issue.