A
A
AlexKvashin212021-03-24 06:06:42
Unity
AlexKvashin21, 2021-03-24 06:06:42

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

2 answer(s)
A
AlexKvashin21, 2021-04-01
@AlexKvashin21

it was necessary to transfer the button scripts to the clicker script in the unit itself

N
namee, 2021-03-24
@namee

Perhaps Instanse is assigned later than the call to the function that accesses this field occurs.
PS
https://translate.google.com/?sl=en&tl=en&text=Ins...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question