Question by
unity_Cp2XopOzBIQZDQ · Aug 12, 2020 at 09:22 AM ·
unity 2dontriggerentertextmesh
Trying to change text after being triggered in the same scene
Hi 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!"; Kindly advise!
Comment
Your answer
Follow this Question
Related Questions
OnTriggerEnter2D not working! Please Help Me!,OnTriggerEnter2D is not working! Please help me! 2 Answers
Check if collider is colliding with something,Check if a collider contains any colliding objects 0 Answers
How to create a 2D slot game in unity step wise step as same as in jetpack joyride? -2 Answers
Unity Multi Application Problem 0 Answers