Using OnTriggerEnter to change UI text

Hey so I’m building a baseball game and I’m using OnTriggerEnter to detect whether or not the baseball enters the strike zone. The strike zone is big enough so it can be detected and the ball isn’t moving too fast. I want to display ("STRIKE!) once it hits the trigger, but nothing is happening. pls help

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Strike : MonoBehaviour {

public AudioSource src;
public ParticleSystem stars;
public Text StrikeText;

private void Start()
{
    StrikeText.text = " ";
}

public void OnTriggerEnter(Collider other)
{
    if (other.gameObject.tag == "ball")
    {
        src.Play();
        Instantiate(stars, transform.position, transform.rotation);
        StrikeText.text = "STRIKE!";
        Destroy(other.gameObject);
        SecondsWait();
        StrikeText.text = " ";
    }
    
    
}
IEnumerator SecondsWait()
{
    yield return new WaitForSeconds(4);
}

}

Hello @purne104!

I briefly looked at your code and I do not see any problem in it. However, I want you to check the collider attached to the strike zone. Make sure “is trigger” is checked and let me know if it works or not.

I hope this helped :slight_smile: