Answer the question
In order to leave comments, you need to log in
Unity, I created a button but it does not respond to a click, how to fix it?
I created a button
Then I created a script for it:
(the button is on the Scroll VIew)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UpButtonHelper : MonoBehaviour
{
public Text DamageText;
public Text PriceText;
public int Damage = 10;
public int Price = 100;
private GameHelper _gameHelper;
// Use this for initialization
void Start()
{
DamageText.text = Damage.ToString();
PriceText.text = Price.ToString();
_gameHelper = GameObject.FindObjectOfType<GameHelper>();
}
// Update is called once per frame
void Update ()
{
}
public void UpClick()
{
if (_gameHelper.PlayerGold >= Price)
{
_gameHelper.PlayerGold -= Price;
_gameHelper.PlayerDamage += Damage;
Destroy(gameObject);
}
}
}
Answer the question
In order to leave comments, you need to log in
just to clarify. is the condition exactly fulfilled?
if (_gameHelper.PlayerGold >= Price)
tried to pull it out from under the scrollrect? almost certainly because of him,
and so many things can be. above the button is something with raycast target ticked.
can hang event triger on content and it intercepts all events for itself and does not start up "below"
so in an empty scene.
-create a scroll view
-add buttons.
-on content we add some Layout.
We get a scrolling list of buttons and each one works.
See how else yours differs from this minimum working set.
on all the screenshots provided, everything is generally correct and adequate.
(although the button's RectTransform is missing and what's on the Content)
It also happens that you accidentally deleted the EventSystem scene element, which is responsible for UI events.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question