Change UI as it hits certain objects

Hello,

I’m wondering what the best solution for changing the UI as it hits certain objects is. I have two ideas on how to do this.

  1. I constantly send a raycast and as I hit an usable object I change the UI to something else.
  2. I try to do the same thing with collision boxes instead and have a trigger box in-front of the player that when it collides with usable objects I change the UI.

But I’m not sure if this is the best way to solve the problem.

What I want to do is that when a player looks at certain objects I want to show them by changing the UI that this is a usable item. But I do not want this to happen when they are for example looking at a wall. If someone else have solved this same problem please tell me the best way to solve this. :slight_smile:

Hi,

If i understand correctly, you have an OnGUI() Function.

Since this function cant really be interacted with like another script, the easiest way i can see to do this, would be to have a boolean which can be updated according to the raycast in the update function. The OnGUI function would then check that boolean when it updats, and then react accordingly just like you would write an if statement in any other part of your code.

Hope this helps :slight_smile:

IEMatrixGuy out.