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
0
Question by metaphysician · Feb 19, 2012 at 12:44 AM · arraytriggersoundclip

Triggering a specific sound in an Array - syntax help likely...

hey folks, another newbie question, likely from a JavaScript sytax angle.

i want to send a message to select a specific loop number and have the receiving Game Object trigger that sound from an array. Heres what i have so far:

 var targetObject : GameObject;
 var soundNum : int;
 
 function OnTriggerEnter()
 {
 targetObject.SendMessage(targetObject, soundNum );
 } 

i believe this sets a Game Object to look for and should send an int variable called numSound to the game object

on the receiving end is an object with an AudioSource on it and this script:

 var clipNumber : AudioClip[];
 
 function PlayNumberSound(soundNum : int)
 {
   audio.clip = clipNumber[soundNum - 1]; // i-1 because array starts at 0
   audio.loop = true;
   audio.play();
 }

this sets up an array of sounds which i would like to pass the value soundNum to from the sending script. the following compiles fine but results in a rather ominous MissingMethodException: Method not found: 'UnityEngine.AudioSource.play'. also the sound does not trigger. when the trigger is reached the loop cuts out but no other loop plays.

i'm suspecting a syntax error in terms of my javascript and have tried variations but no luck so far.

any help vastly appreciated,

scott

Comment
Add comment · Show 1
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 syclamoth · Feb 19, 2012 at 01:11 AM 0
Share

Funny that this compiles. I don't use JS much, so I'm not sure what works and what doesn't- but I really wouldn't expect this to.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by syclamoth · Feb 19, 2012 at 01:10 AM

Spelling, in programming, is very important. In this case, you need to capitalise the correct words-

 audio.play();

isn't a recognised function.

 audio.Play();

however, is.

As for your 'index - 1' thing, seriously, just learn to 0-index things. It's not that much of a logical stretch, and it'll make your code more readable.

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 metaphysician · Feb 19, 2012 at 06:48 AM 0
Share

thanks for the help! i got the 'index -1' thing as part of some starting code i copied from somewhere else. anyway i figured it was something stupid like not capitalizing.

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

6 People are following this question.

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

Related Questions

Sound plays when instantiated and not on trigger. 1 Answer

How to set a specific gameobject in an array false when it collides with a trigger. 1 Answer

audio trigger keydown 1 Answer

Make triggered sound audible anywhere 2 Answers

Random Array of sounds for Random Game Object 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