I'm trying to change my text if b1 is triggered.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Player_Start : MonoBehaviour
{
[SerializeField] public TextMeshProUGUI textTest;
public void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("b1"))
{
textTest.text = "Now let's move the right leg up!";
transform.GetChild(0).gameObject.SetActive(false);
transform.GetChild(1).gameObject.SetActive(true);
}
if (collision.gameObject.CompareTag("b2"))
{
transform.GetChild(1).gameObject.SetActive(false);
transform.GetChild(3).gameObject.SetActive(true);
}
}
}
I get an error saying
NullReferenceException: Object reference not set to an instance of an object Player_Start.OnTriggerEnter2D (UnityEngine.Collider2D collision) (at Assets/Player_Start.cs:16)
Line 16 says:
textTest.text = "Now let's move the right leg up!";