기술 자료

​
​

Development

User Acquisition

Monetization

산업 분야

Unity Studio

Open Unity Studio

Unity Studio

이 페이지는 선택한 언어로 제공되지 않습니다.
​
​
Unity Studio
  • What's new in Unity Studio
  • Introduction to Unity Studio
  • Launch Unity Studio
  • Create your first Unity Studio project
  • Develop with Unity Studio
    • The Unity Studio interface
    • Save your progress
    • GameObjects
    • Assets
    • Materials
    • Scene settings
    • Logic
      • Introduction to Logic
      • Create a Logic script
      • The Logic Editor interface
      • Methods, variables, and parameters
      • Nodes
      • Logic examples
        • Use a button to transform a GameObject
        • Hide or show a User Interface (UI) element
        • Trigger an animation on key press
        • Adjust scene lighting with a button
        • Interact with an asset after an event
        • Display the name of a GameObject on hover
        • Enable or disable a property on a GameObject
        • Play audio when you click an object
        • Mute and unmute audio with the toggle element
        • Use sliders to change a material's color
    • The UI Creator
    • Animation
    • AI features
  • Collaborate in Unity Studio
  • Export drafts to the Unity Editor
  • Publish and share
  • Troubleshooting Unity Studio issues
  • Report bugs and share feedback
  • Manage your analytics and marketing preferences
  1. Unity Studio
  2. Develop with Unity Studio
  3. Logic
  4. Logic examples

Play audio when you click an object

Play audio when the user clicks on an object.
읽는 시간 3분
최근 업데이트: 7달 전

In this example, you set up a Logic script to play audio when the user clicks on an object. Use these steps to set up similar interactions with audio in your scene. For example, you can play audio when the user clicks to open a door or play music on a radio.
1

Add an interactive object to your scene

  1. In the Hierarchy panel, select Add (+) and choose an object to add to your scene. For example, a cube or sphere.
  2. Select the object in the Hierarchy panel to open the Inspector panel.
  3. In the Inspector panel, make sure the object has a Collider component to detect user interaction. For example, a Box Collider or Sphere Collider.
    • If the object doesn't have a collider, select Add Component and add the appropriate collider.
2

Add audio to your object

  1. In your object's Inspector window, select Add Component > Audio Source. This adds an Audio Source component to your object, which plays audio clips in your scene.
  2. Find an audio clip in the My Assets folder or select Add Assets to import one.
  3. Drag your audio clip into your object's Audio Source component in the Audio Clip field.
  4. Disable Play On Awake so the audio doesn't play immediately when the scene starts.
3

Create and attach a Logic script to your object

  1. In the Hierarchy panel, select your object.
  2. Select Add Component (+).
  3. In the New Logic field, enter a name for your script and press Create and Edit. Unity Studio creates a new Logic script and automatically attaches it to your object. The Logic Editor opens so you can build your script.
4

Set up the initial logic in the Logic Editor

  1. In the Logic Editor, drag in a When node.
  2. Add a Clicked On event inside the When node's socket.
  3. Drag the
    me
    variable into the Clicked On node's socket. This variable references the object the script is attached to, so the event listens for clicks on this object.
5

Play the audio on click

  1. Drag an If node inside the When node.
  2. Move a Not node into the first socket of the If node.
  3. Drag the
    me
    variable into the Logic Editor, expand it, and choose Get Component > Audio Source > isPlaying. This creates a Boolean node that checks if the audio is currently playing.
  4. Drag the new me > Audio Source > isPlaying node into the Not node's socket.
  5. Add another
    me
    variable into the Logic Editor, expand it, and choose Get Component > Audio Source > Play.
  6. Place the me > Audio Source > Play node inside the If node.
Screenshot of an example Logic script that plays audio on click.

Example Logic script to play audio on click.

This logic checks if the audio isn't currently playing when the user clicks the object, and if so, it plays the audio. 7. Close the Logic Editor.

Additional resources

  • Supported asset file formats
  • Logic examples
  • Audio Source

Copyright © 2026 Unity Technologies
법률 정보개인정보 처리방침쿠키Documentation Terms of Use개인 정보 판매 또는 공유 금지개인정보 보호 선택(쿠키 설정)

'Unity', Unity 로고 및 기타 Unity 상표는 미국 및 기타 지역 내 Unity Technologies 또는 그 계열사의 상표 또는 등록상표입니다(자세한 내용은 여기에서 확인하세요). 기타 명칭 또는 브랜드는 해당 소유자의 상표입니다.

일부 페이지는 편의를 위해 기계 번역되었으며 부정확한 내용이 있을 수 있습니다. 정보가 상충되는 경우, 영어 버전을 우선으로 참조하세요.

  • 보고 있는 페이지
    • Additional resources


이 페이지의 문제 보고