Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Mint92 · Nov 14, 2013 at 10:15 PM · triggersoundpickup

Playing sound through pickup trigger

Hey guys, I'm a bit confused to why my sound is not playing when I go through an object

using UnityEngine;

using System.Collections;

 public class Jewels : MonoBehaviour 
 
 {
     public GUIText jewelsText;
     public GUIText winText;
     public AudioClip Pickup;
     private int jewels;
     
 
 
     // Use this for initialization
     void Start () 
     {
         jewels = 0;
         SetJewelsText();
         winText.text = "";
     }
 
     void OnTriggerEnter(Collider other)
     {
         if(other.gameObject.tag == "Pickups")
         {
             other.gameObject.SetActive(false);
             jewels = jewels + 1;
             SetJewelsText();
         }
         if (Pickup)
         {
             audio.clip = Pickup;
             audio.Play();
         }
 
     }
     
     void SetJewelsText()
     {
         jewelsText.text = "jewels:" + jewels.ToString();
         if(jewels >=20)
         {
             winText.text = "You Collected all the jewels!";
         }
     }
     
 }
     
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tanshaydar · Nov 14, 2013 at 10:30 PM 0
Share

Are you sure your Collider is set to isTrigger?

avatar image kristi-knupp · Mar 29, 2016 at 05:15 PM 0
Share

I just did the Roll a Ball Tutorial and am trying to figure out how to do the same thing. Call a sound when I pick up each cube. Does this code need to be placed in the "Player" script I have currently or can I make a new Pick Up's script ?

Thanks, $$anonymous$$risti

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mint92 · Nov 14, 2013 at 11:17 PM

I get an error "There is no AudioSource attached to the "Player" game object, but a script is trying to access it.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ThePunisher · Nov 15, 2013 at 12:01 AM 0
Share

post comments using the "add new comment" button. Delete your accidental answer when you get a chance.

avatar image
0

Answer by Psycho8Vegemite · Mar 29, 2016 at 06:42 PM

Make sure that both gameObjects have a collider, and that the gameObject that is tagged "Pickups", has 'Is Trigger' set to true.

Also on either gameObject, one of them should have a rigidbody to actually register collisions. Due to one of the colliders being set to 'Is Trigger'. The rigidbody won't react to it, just register it and therefore have 'OnTriggerEnter()' be called.

Along with this I changed the audio to use an AudioSource:

GetComponent<AudioSource>().whatever

so add that on as well unless your not using Unity5; if so 2D/3D sound can be achieved with the 'Spatial Blend' within the component.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sound plays when instantiated and not on trigger. 1 Answer

audio trigger keydown 1 Answer

How to make 2D object trigger a sound once each time it passes 2D player in 3D game?,I want to play a sound once each time passes near my player 0 Answers

Trigger sound when pressing button 2 Answers

Error CS0116 : A namespace can only contain types and namespace declarations. PLEASE HELP ME! 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges