Question by
DarkDra9on555 · Feb 27, 2016 at 03:44 PM ·
guibutton
GUI button not working?
I have two scripts. A script to make a button when the player is wishing a certain distance,
public class Distance : MonoBehaviour {
public float maxDist = 3;
public Transform t;
public string text1;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
void OnGUI()
{
float dist = Vector3.Distance (t.position, this.transform.position);
if (dist < maxDist)
{
GUI.Box (new Rect(10, 10, 100, 90), text1);
if(GUI.Button (new Rect(20, 40, 80, 20), "Yes"))
{
Quests.isQuestOne = true;
}
}
}
}
and a script that prints in the debug log when isQuestOne = true.
public class Quests : MonoBehaviour {
public static bool isQuestOne = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
}
void QuestOne()
{
if (isQuestOne == true)
{
Debug.Log ("Yay");
}
}
}
When I click the button however, nothing seems to be happening. What am I doing wrong, and how can I fix it?
Comment
Answer by Dank_Mushies · Apr 23, 2016 at 05:35 PM
I'm not completely if this will help, but i noticed that your void QuestOne() isn't called from anywhere try adding it to a method that is being called.
//although i wouldn't recommend using Update all the time for things like this
void Update()
{
QuestOne();
}
Your answer

Follow this Question
Related Questions
Mouse click not registered correctly using CRT shader 0 Answers
UI Text Editing Problem, What's Wrong? Need Anybody to Assist 1 Answer
Trouble with GUI Button Level switching. 0 Answers
Get child UI button size 0 Answers
Animated GUI button 0 Answers