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 /
This question was closed Nov 12, 2019 at 10:03 PM by gonzalitosk8.
avatar image
-1
Question by gonzalitosk8 · Nov 13, 2014 at 04:03 AM · audiosoundcarwaitforseconds

someone is there?

Hi! I have a question to apply a "stop" to this script .. to tighten ("shiftUp" button) I want the audio stops for a while (in this case the value of ShiftTime)

Here I give you the script in c # : using UnityEngine; using System.Collections;

public class prueba : MonoBehaviour {

 public AudioClip test;
 public float testvolumenMax = 1;
 public float testpitch = 1;
     public float ShiftTime = 0.8f;

 AudioSource testSource;
 Drivetrain drivetrain;
 float volumeFactor;
 int i,k;    
 
 AudioSource CreateAudioSource(AudioClip clip, bool loop, bool playImmediately, Vector3 position) {
     GameObject go = new GameObject("audio");
     go.transform.parent = transform;
     go.transform.localPosition = position;
     go.transform.localRotation = Quaternion.identity;
     go.AddComponent(typeof(AudioSource));
     go.audio.clip = clip;
     go.audio.playOnAwake = false;
     if (loop==true){
         go.audio.volume = 0;
         go.audio.loop = true;
     }
     else 
         go.audio.loop = false;
     
     if (playImmediately) go.audio.Play();
     
     return go.audio;
 }

 void Start () {

     drivetrain=GetComponent<Drivetrain>();
     testSource = CreateAudioSource(test, true, true,Vector3.zero);
 }

 void Update () {
 
     if(Input.GetButton ("Throttle")){
         if(this.drivetrain.rpm>100){
         {if (!testSource.isPlaying) testSource.Play();}
         float factor=drivetrain.rpm/drivetrain.maxRPM;
         testSource.volume = 0 + testvolumenMax*factor;
         testSource.pitch = 0.1f + testpitch*factor +0.3f;
         }
     }
     else
     {
         float factor=drivetrain.rpm/drivetrain.maxRPM;
         testSource.volume = 0.1f + testvolumenMax*factor-0.1f;
         testSource.pitch = 0.1f + testpitch*factor -0.15f;
     }
 }

}


how I can apply a stop time to audio? help me? Thanks!

Comment
Add comment · Show 3
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 richyrich · Nov 13, 2014 at 10:50 AM 0
Share

ShiftTime is not defined in your script.

In order to stop the audio, you need to keep a record of all the 'go' objects you are creating - a them to a List. Then set a function to execute after 'ShiftTime' time, after the creation. When the new function executes, remove the first item from the List.

Hope this helps.

avatar image gonzalitosk8 · Nov 13, 2014 at 03:57 PM 0
Share

I honestly do not understand anything!

avatar image richyrich · Nov 13, 2014 at 06:58 PM 0
Share

Did the latest answer not fix the current problem?

1 Reply

  • Sort: 
avatar image
0

Answer by richyrich · Nov 13, 2014 at 03:59 PM

Add another function:

 IEnumerator StopAudio(AudioSource asToStop)
 {
     yield return new WaitForSeconds(ShiftTime);
     asToStop.Stop();
 }

In Start, underneath testSource = CreateAudioSource(test, true, true,Vector3.zero); add:

 StartCoroutine(StopAudio(testSource ));
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 gonzalitosk8 · Nov 13, 2014 at 10:31 PM 0
Share

does not work! you could do it?

:(

Follow this Question

Answers Answers and Comments

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

Related Questions

Multiple Cars not working 1 Answer

play audio for few seconds on key hit 1 Answer

Vehicle help 1 Answer

Gun Audio reverbs off of Terrian- sounds horrible- What can I do? 0 Answers

Wait for sound is played 2 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