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 saitoFOX · Jul 12, 2012 at 11:08 AM · soundvar

Faulty Code.

var crashSound : AudioClip;

var otherObject : GameObject;

var soundplayed = false;

function Update(){

  print ("Scary Noise");

if (otherObject.renderer.isVisible)

{

  if(soundplayed==false)
  {
   Debug.LogWarning("Test sound");
   otherObject.audio.PlayOneShot(crashSound);
   soundplayed = true;

}

  }

if (otherObject.renderer.isnotVisible)

{

soundplayed = false;

}

}

that code does'nt seem to want to work. what im trying to do is if otherObject is in view play sound. and if not. do nothing lol. seems to not want to work. a little help?
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 Maddogc · Jul 12, 2012 at 07:03 PM 0
Share

$$anonymous$$aybe the soundplayed = true part deactivates the if statement too soon and the sound can't be played completely - you could try this inside your if statement:

otherObject.audio.PlayOneShot(crashSound);

yield WaitForSeconds (crashSound.clip.length);

soundplayed = true;

In addition you should make sure that the otherObject has an AudioSource component attached.

avatar image saitoFOX · Jul 12, 2012 at 07:11 PM 0
Share

no thats not it. still does'nt want to play.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by idunlop_oefun · Jul 12, 2012 at 11:13 PM

 if (otherObject.renderer.isnotVisible)

What is 'isnotVisible'? Does that compile?

Should it not be:

 if (otherObject.renderer.isVisible == false)
Comment
Add comment · Show 12 · 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 saitoFOX · Jul 12, 2012 at 11:24 PM 0
Share

Can you help me via skype... it takes like 6 hours per answer here...

avatar image idunlop_oefun · Jul 12, 2012 at 11:25 PM 0
Share

Possibly - but can you do me a favor and answer the question.

avatar image saitoFOX · Jul 12, 2012 at 11:26 PM 0
Share

isnotVisable does compile... but i dont think it works :I

also add me on skype $$anonymous$$iro.tygira

avatar image idunlop_oefun · Jul 12, 2012 at 11:31 PM 0
Share

Can you post the complete script? I use C# so I'm not familiar with all of the JS syntax - however I'm puzzled that it compiles.

avatar image Bunny83 · Jul 13, 2012 at 12:17 AM 1
Share

DON'T ask for help outside of UA. Unity Answers is a knowledge database. The questions and answers should help others as well. When you solve the issue somewhere else you cheat this community.

isnotVisible doesn't exist on the renderer component. You probably don't have a pragma strict at the top of your script, so it would compile almost everything, but that doesn't mean it works.

This is the correct answer. You have to either compare it to false or invert it, which is the most common way:

 if (!otherObject.renderer.isVisible)

Note the "!". It's not a typing mistake, it's the logical negation operator which turns true into false and false into true.

btw. ever heard of "else"? ;)

 if (otherObject.renderer.isVisible)
 {
     if(soundplayed==false)
     {
         // [...]
     }
 }
 else
 {
     soundplayed = false;
 }
Show more comments
avatar image
0

Answer by cdarne · Jul 12, 2012 at 10:55 PM

Hi,

Maybe the otherObject GameObject has no "Audio Source" (or his volume is set to 0) or maybe the Camera Object has no "Audio Listener" (or it's deactivated)? Maybe you muted your computer's speakers ? (sounds obvious but it already happened to me...).

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 saitoFOX · Jul 12, 2012 at 11:01 PM 0
Share

it does...

it wont load the "soundplayed = false;" at the end, so it wont repeat...

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

8 People are following this question.

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

Related Questions

i want an object rotate 45 degrees more than an other one 1 Answer

Networking Gun Fire Sound 1 Answer

Why does my var speed say it is wrong 2 Answers

Parse music files for specific notes (DDR-style game) 2 Answers

Play sound when out of ammo 0 Answers


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