I have a very simple subroutine in one code that will set the .text component of my UI canvas to a certain string. This works without problems. In the same routine there is an if-statement that will again (re)set the .text component if a certain key is pressed. This does NOT work, for some odd reason.
The transform.position will run, but not the .text = “” line. Anyone got any ideas as to why?
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag(“Finish”))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
}
if (other.gameObject.CompareTag(“floorfall”))
{
resetText.text = “Press R to reset”;
bool rpress = Input.GetKeyDown (“r”);
if (rpress == true)
{
ball.transform.position = startpos;
resetText.text = “”;
You should not rely on keyInputs in OnTriggerEnter, your key has to be registered as ‘pressedDown’ (holding it does not count here) when you enter the trigger which will most-likely fail.
Are you sure the position is set through this code? I can’t imagine why this would be executed while setting the text wouldn’t if you happen to press down the key in the correct moment.
Man, you were right on both occasions - it seems that the positoin was set in another subroutine (void FixedUpdate) and not in the OnTriggerEnter routine.
I moved my .text component change to this subroutine instead and, of course, that works like a charm.
Still a bit of a noob here, much obliged for the help!