- Home /
Unity Button Responding Very Slowly
I have several buttons that the user is meant to click on them and it would run a function: SetMultiples() and update some game statistics. However, it seems that rather than executing the function immediately, there is a consider delay of 4-5 seconds before the function is called.
I have tried to call the SetMultiples() to respond to a certain keyboard and it seem to run the function immediately.
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine;
public class MultiplesButtonClick : MonoBehaviour {
public PlayerSelection playerSelection; //enum player selection variable
public Button assignedButton; //button assigned to this script
public GameObject planetManager; //reference to planet manager
public Color selectedColor;
public Color originalColor;
// Use this for initialization
void Start () {
planetManager = GameObject.FindGameObjectWithTag("PlanetManager");
assignedButton = GetComponent<Button>();
assignedButton.onClick.AddListener(SetMultipes);
originalColor = GetComponent<Button>().colors.normalColor;
selectedColor = Color.gray;
}
// Update is called once per frame
void Update () {
}
//Function to set the multiples player wants to buy/sell
void SetMultipes()
{
int qty = 0;
switch (playerSelection)
{
case PlayerSelection.ONE:
qty = 1;
break;
case PlayerSelection.FIVE:
qty = 5;
break;
case PlayerSelection.TEN:
qty = 10;
break;
}
if (planetManager)
{
planetManager.GetComponent<PlanetManager>().ShowMultiples(qty);
}
}
}
Can anyone explain to me what am I doing wrongly to cause the delay? I have attached a screen shot of how I have arranged my UI canvas. This script is attached to "One", "Five", "Ten" which are all butttons.
This shows the settings on the canvas itself
Your answer
Follow this Question
Related Questions
executing As long as button still pressed 1 Answer
Getting almost nowhere with my buttondrag script 1 Answer
Make button inside ScrollView move when ScrollView scrolls 1 Answer
GUIText Problem With MENU 1 Answer
Gui Button Solid 2 Answers