Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 pantaryl · Nov 10, 2012 at 12:43 AM · soundaudiosourceaudioclipplaybackwards

Play AudioSource Backwards

Hello all –

I'm trying to play an AudioSource backwards. I've done a bit of reading and can't seem to figure out if this is an actual possibility.

What I'm currently trying to do is:

  • First I start playing the audioSource.

  • Then I set the audioSource.time equal to the audioSource.clip.length.

  • Then I set the audioSource.pitch to -1.

However, this doesn't seem to work.

Any ideas?

Comment
Add comment
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

2 Replies

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

Answer by Seth-Bergman · Nov 10, 2012 at 01:08 AM

first of all, note that AudioSource.time may not actually represent the actual time of the clip (with compressed audio)

http://docs.unity3d.com/Documentation/ScriptReference/AudioSource-time.html

I'm not really sure what the "correct" way would be to handle that line, probably using timeSamples vs clip.samples

to be safe, I would use one less

 audio.timeSamples = audio.clip.samples - 1;
 audio.pitch = -1;
 audio.Play();

I've tested this and it works

but not without the "-1" in "audio.clip.samples - 1;" though, so I guess once you reach the last sample, it automatically "resets" or whatever, so keep that in mind..

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
avatar image
1

Answer by ADISKING1 · Aug 02, 2020 at 08:42 PM

Temporary Fix I came up with

 using System.Collections;
 using UnityEngine;
 
 public class AudioPlayer : MonoBehaviour
 {
     private AudioSource audioSource;
 
     void Start()
     {
         audioSource = GetComponent<AudioSource>();
     }
 
     public void PlayAudio(AudioClip audioClip)
     {
         audioSource.pitch = 1;
         audioSource.clip = audioClip;
         audioSource.Play();
 
     }
     public void PlayReverseAudio(AudioClip audioClip)
     {
         audioSource.pitch = -1;
         audioSource.loop = true;
         audioSource.clip = audioClip;
         audioSource.Play();
         StartCoroutine(StopLoop());
     }
 
     public IEnumerator StopLoop()
     {
         yield return new WaitForSeconds(1f);
         audioSource.loop = false;
     }
 
 }
 
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 tcz8 · Oct 26, 2020 at 05:42 PM 0
Share

Thank you!
BTW seems like you stop it after only 1 second, I assume as soon as it starts playing you can disable the loop. Why not use "yield return null" to wait one frame?

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

13 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

Related Questions

Can not play a disabled audio source persistent problem 0 Answers

Unity plays only a few gameobject's sound 2 Answers

How do I play audio source on Maximize on Play / Audio Source wont play on Maximize 0 Answers

Audio clip not playing 1 Answer

How to get decibel's value of game's sound? 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