Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ughdeeb · Nov 20, 2018 at 12:57 PM · inspectoraudioclipscritpingserializedobject

How to add field in inspector to change audio on delay

Hi,

I have the following script for playing audio after a certain amount of time has elapsed. Instead of defining the length of time in the script itself, I'd like to add a serialized field so that I can use the script on different game objects and manipulate the time elapsed before playing audio in the Inspector. New to coding. Thanks.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class StartAudioOnDelay : MonoBehaviour {

 AudioSource myAudio;

 // Use this for initialization
 void Start () {
     myAudio = GetComponent<AudioSource>();
     myAudio.PlayDelayed(3.0f);
 }

 
 // Update is called once per frame
 void Update () {
     
 }

}

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

1 Reply

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

Answer by mlnczk · Nov 20, 2018 at 01:03 PM

 [Range(0,10)]  // will create editable slider in inspector from values 0 to 10
 public float audioLenght;
 
 void Start(){
     myAudio = GetComponent<AudioSource>();
     myAudio.PlayDelayed(audioLenght);
 }
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 ughdeeb · Nov 20, 2018 at 03:22 PM 0
Share

Thank you so much @mlnczk!

Now that I think about it, this is a really annoying way to go about this. I am basically using this to manage 2-3 different pieces of audio within a scene, setting the 2nd and 3rd pieces of audio to deay its start so that it will play after each one finishes.

Using code, is there a way to detect when one audio is finished, and when that audio is finished, to have the 2nd audio play right after, and then a 3rd and so on? $$anonymous$$aybe this will incur less perforamnce costs in Unity(?)

avatar image mlnczk ughdeeb · Nov 21, 2018 at 08:25 AM 1
Share

Hmmm maybe try using these AudioSource methods. https://docs.unity3d.com/ScriptReference/AudioSource.SetScheduledStartTime.html https://docs.unity3d.com/ScriptReference/AudioSource.SetScheduledEndTime.html Never used that but I recommend checking always Unity's documentation its pretty good and if you want to do something with e.g AudioSource you can easily check all available methods and examples and see if there is a solution for your problem. Cheers!

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

99 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 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 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 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

Why are the children of my Serialized Property not being drawn? 1 Answer

Custom Inspector: Using 'serializedObject' to access inherited members 1 Answer

Unity Inspector Choose C# object from list 0 Answers

Is it better/more performant to make a SerializedProperty reference or get the reference as needed from the serializedObject reference? 0 Answers

Inspector doesn't always find candidate ScriptableObjects for serialized fields 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