Answer the question
In order to leave comments, you need to log in
Error: Object reference not set to an instance of an object. Why can't I move buttons?
I wrote the code for the buttons, now I want to transfer the buttons from the canvas to the panel, when I transfer them they do not work and an error pops up
Code:
using UnityEngine;
using TMPro;
using UnityEngine.EventSystems;
public class AmplifierPref : MonoBehaviour, IPointerClickHandler
{
[SerializeField]
private TextMeshProUGUI level;
[SerializeField]
private TextMeshProUGUI price;
private DamageAmplifier amplifier;
private canvas group;
public void SetData(DamageAmplifier amplifier)
{
group = GetComponent();
this.amplifier = amplifier;
UpdateUI();
}
public void UpdateUI()
{
level.text = "x" + amplifier.Level;
price.text = "$" + amplifier.Price;
group.alpha = Clicker.Instanse.Money >= amplifier.Price ? 1 : .5f;
}
public void OnPointerClick(PointerEventData eventData)
{
if (Clicker.Instanse.Money < amplifier.Price)
return;
Clicker.Instanse.AddMoney(-amplifier.Price);
amplifier.LevelUp();
UpdateUI();
}
}
Answer the question
In order to leave comments, you need to log in
it was necessary to transfer the button scripts to the clicker script in the unit itself
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question