Question by
xxxsashasxxx · Feb 02, 2018 at 05:19 PM ·
inputgameobjectscollision2d
Activating GameObject in a special zone with a button press
Hello there! I am trying to write a script which will write a text once I step on a special object and press a special button.
I've got a GameObject which is the special object I gonna step on and another GameObject with TextMesh attached to it. Second object is deactivated. Here is a script which will activate my TextMesh object:
void OnTriggerEnter2D(Collider2D other)
{
if (Input.GetButton ("Jump") && other.gameObject.CompareTag("Text"))
{
other.gameObject.transform.GetChild(0).gameObject.SetActive(true);
}
}
But the problem is that it does nothing. How can I fix it?
Comment
Best Answer
Answer by xxxsashasxxx · Feb 03, 2018 at 04:48 PM
Sorry for the stupid question! I just had to change "OnTriggerEnter2D" to "OnTriggerStay2D".
Your answer
![](https://koobas.hobune.stream/wayback/20220612151812im_/https://answers.unity.com/themes/thub/images/avi.jpg)