Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question GameObject Interaction Questions

Discussion in 'Editor & General Support' started by SellswordEntertainment, Jun 16, 2020.

  1. SellswordEntertainment


    Jun 13, 2020
    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!
  2. Obviously whatever you do with the object, what functions you call when you interact is up to you. If you "pickup" something or play and audio has no meaningful difference.