[Solved] Having an issue connecting buttons to guess functions

Hello, I’m having issues with getting the buttons to connect to my guessing scripts.

In the instructional video, the function on the buttons are set to guess higher/lower functions, although when I connect my script to the buttons, the only function option I get is either “No Function” or MonoScript - script name.

I’m sure I’ve just been an idiot and missed something, but I’ve been trawling through for a while and can’t find a fix, does anyone know what I’ve done wrong?

Here’s my code, if it helps:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class NumberWizard : MonoBehaviour {

// Use this for initialization
int max;
int min;
int guess;
int maxGuessesAllowed = 10;

public Text text;

void Start () {
	StartGame ();
}

void StartGame () {
	max = 1000;
	min = 1;
	guess = 500;
}

public void GuessLower (){
	max = guess;
	NextGuess ();
}

public void GuessHigher (){
	min = guess;
	NextGuess();
}

void NextGuess () {
	guess = (max + min)/2;
	text.text = guess.ToString();
	maxGuessesAllowed = maxGuessesAllowed -1; 
	if (maxGuessesAllowed <= 0){
		Application.LoadLevel("Win");
	}
}

}

Hello @Ynsin,

Have you dragged your LevelManager into the OnClick event for the button?

That was exactly it. Thanks :slight_smile:

You’ee more than welcome, glad you can move forward again :slight_smile:

Privacy & Terms