Hi all,
I’m working on my first Unity project, and am having an issue figuring out how to get a Player to be able to interact with a GameObject. Here’s what I’m trying to do:
My intent is that the Player should be able to:
- Approach a GameObject
- Within a certain distance of a GameObject, press a specified key
- When the key is pressed, audio plays from the GameObject
I’m assuming the distance checking involves Raycasting, but I haven’t been able to figure out how to utilize the Raycast hit to then make the Player eligible to press the specified key. I also have not been able to figure out how to trigger the audio on key press when related to a GameObject.
For reference, I’m looking to create a simple ‘Walking Simulator’ where the player walks up to an object (like a tape recorder) presses a key to interact with it, and the audio plays from the item.
I’ve searched around for threads/tutorials online, but haven’t been able to find any help on what I assumed was a relatively common feature. If anyone can point me in the right direction, I would be greatly appreciative!