Я программирую на unity 2D и у меня такая ошибка:
NullReferenceException: Object reference not set to an instance of an object
UI.OnTriggerStay2D (UnityEngine.Collider2D other) (at Assets/Object/Code/UI.cs:21)
Вот код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class UI : MonoBehaviour
{
public trigger_test zacaz1;
public trigger_test1 zacaz2;
public TextMeshProUGUI text;
public TextMeshProUGUI tet2;
void Start()
{
zacaz1 = GetComponent<trigger_test>();
zacaz2 = GetComponent<trigger_test1>();
}
private void OnTriggerStay2D(Collider2D other)
{
text.text = other.name;
if (other.name == zacaz1.right_cargo.name)
{
tet2.text = "Trade zone №1";
}
else
{
tet2.text = "There is no order";
}
if (other.name == zacaz2.right_cargo.name)
{
tet2.text = "Trade zone №2";
}
else
{
tet2.text = "There is no order";
}
}
private void OnTriggerExit2D(Collider2D other)
{
text.text = "There is nothing here";
}
}