a)Using the FPS controller: I want to be able to walk to an object, press a key and have that object display text on a ui canvas.
b)Then, be able to walk to a second object and do the same but have it display it’s own unique message.
c)I would like to have the source text be retrieved from text files/json/xml (rather than entered manually in the inspector) I’d be happy to entertain suggestions.
I have been doing tutorials for two days to try and do this, I have managed to do perform (a) and (b) in third person but not (c) and not using the FPS controller.
The frustration is real, any pointing in the right direction would be INCREDIBLY welcome. SOS.
We need to narrow down to what specifically you’re having trouble with. What method are you using right now to achieve a and b? I’m curious because I don’t think it should matter whether you’re in first-person or third-person.
As for reading from text files, you can do this with the .NET File class (or the stripped down UnityEngine File class). You will have to create your own method for turning the byte array into value assignments at the project level.
For JSON, you can use the JsonUtility class to translate between JSON objects and Unity serializable objects. We need more info on where this JSON comes from, though. File? Unity data? A server?
Hi Hyblademin thank you for the response, I’ll try and make my question more concise and instead of going for multiple problems at once get the base going first.
If I were to use OnTriggerEnter for a specific box collider. How would I have this display a UI element on the screen…a button or piece of text for example specific to that item, which I would then get rid of using OnTriggerExit.
The overall effect I am trying for is making objects that can display information about themselves when interacted with.
For this, I would just set up the UI object how you want it to appear, then disable it in the editor. Inside your OnTriggerEnter() definition for the appropriate object, enable the object to make it appear using GameObject.SetActive(). Disable the object again using the same method in the OnTriggerExit() definition.
There may be more flexible ways to do this depending on what type of UI object should be shown. for example, if it’s a Text object, then you could set the Text.text to null in the editor, then set and clear the text value as needed in scripts. This way, you can use the same text element for more than one type of alert.