• 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 CallToAdventure · Jun 07, 2011 at 01:38 PM · android

Audio not looping on Android

I have a bit of a problem playing the audio on a machine gun on Android. The code is from stock machine gun (for the audio part)

 function LateUpdate() {
     if (muzzleFlash) {
         // We shot this frame, enable the muzzle flash
         if (m_LastFrameShot == Time.frameCount) {
             muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward);
             muzzleFlash.enabled = true;
             
             if (audio) {
                 if (!audio.isPlaying)
                     audio.Play();
                     audio.loop = true;
             }
         } else {
         // We didn't, disable the muzzle flash
             muzzleFlash.enabled = false;
             enabled = false;
             
             // Play sound
             if (audio)
             {
                 audio.loop = false;
             }
         }
     }
 }

And here's the code for firing the weapon:

     if (GUI.RepeatButton (new Rect (644, 373,107,107), "", fireStyle)) 
         BroadcastMessage("Fire");

I attached an audio source to the weapon and set it to loop (disabling that option won't work either).

I am thinking this must have something to do with the RepeatButton code, which I need since the player should keep the button pressed as long as it wants to fire as opposed to short bursts. Any ideas where I might be doing it wrong? Thanks!

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 aldonaletto · Jun 07, 2011 at 04:58 PM 0
Share

I don't know if it can help, but at least the audio stuff worked fine for me (in a Windows system). Use some traps -Debug.Log, for instance - to check if the buttons are doing what you expect.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by alex.loren · Jun 07, 2011 at 06:55 PM

I have not tested the above code, but one thing that does stand out to me from the above; is that you are setting the audio to loop after you have already played it. I am not 100% on how Unity handles these things, but try setting the audio.loop to true before you play off the audio.

Comment
Add comment · Show 2 · 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 CallToAdventure · Jun 07, 2011 at 07:38 PM 0
Share

Well, tried it all. Apparently the RepeatButton doesn't really work like Input.GetButton (on Windows while pressed it will keep broadcasting the fire message); So is there maybe a way to map what Input.GetButton does to a GUI button?

avatar image alex.loren · Jun 07, 2011 at 08:26 PM 0
Share

One other thing that comes to $$anonymous$$d right now, is why not have all of your buttons as sprites rendered by a separate orthogonal camera and within your update loop preform a raycast if a touch event has been received to see if the player is 'pressing' the button. You could also try, to save yourself a raycast every frame, saving the initial touch position and comparing it every X frames with the new position; if it has changed send another raycast to see if they have left the button area. Just my thoughts right now, can't dig too deep into it as I am not at my home or development computers at this time.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Android controls 1 Answer

ridiculous load time using Resources.Load() on android build 0 Answers

Get vertical FOV of Google Cardboard stereo camera 0 Answers

Using an Android tablet as input device for a desktop app 2 Answers

OpenGL 2.0 Problem 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