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 NCsoft · Jul 10, 2014 at 02:09 AM · audioloopsource

AudioSource.PlayClipAtPoint loop ?

 using UnityEngine;
 using System.Collections;
 
 public class login2 : MonoBehaviour
 {
     public GUIStyle ImageBackground;
     public GUIStyle ImageButtonRegistration;
     public GUIStyle ImageButtonLogin;
     public AudioClip SoundBackground;
     public AudioClip SoundButtonClick;
     public AudioClip SoundButtonOver;
     public string lastTooltip = "";
     
     void Start ()
     {
         AudioSource.PlayClipAtPoint(SoundBackground, transform.position);
     }
     
     void OnGUI ()
     {
         GUI.Box(new Rect((Screen.width - 246 ) / 2, (Screen.height - 128 ) / 2, 246, 128), "", ImageBackground);
         if(GUI.Button(new Rect((Screen.width - 180 ) / 2, (Screen.height - -150 ) / 2, 81, 28), new GUIContent("", "SoundButtonOver"), ImageButtonRegistration))
         {
             AudioSource.PlayClipAtPoint(SoundButtonClick, transform.position);
         }
         if (GUI.Button (new Rect ((Screen.width - -15) / 2, (Screen.height - -150) / 2, 81, 28), new GUIContent("", "SoundButtonOver"), ImageButtonLogin))
         {
             AudioSource.PlayClipAtPoint(SoundButtonClick, transform.position);
         }
         if (Event.current.type == EventType.Repaint && GUI.tooltip != lastTooltip) {
             if (GUI.tooltip != "")
                 AudioSource.PlayClipAtPoint(SoundButtonOver, transform.position);
             lastTooltip = GUI.tooltip;
         }
     }
 }

alt text

how add to loop function "AudioSource.PlayClipAtPoint(SoundBackground, transform.position); " ?

code.png (51.7 kB)
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
1

Answer by Nerevar · Jul 10, 2014 at 09:47 AM

Hello,

That is not very safe but it should work:

 void Start ()
     {
         AudioSource.PlayClipAtPoint(SoundBackground, transform.position);
         GameObject source = GameObject.Find ("One shot audio");
         source.audio.loop = true;
     }


I don't know if there is a better way to get the AudioSource generated with PlayClipAtPoint(), if only this function could return the source it would be simpler and safer.

cheers

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
0

Answer by Flickayy · Jul 10, 2014 at 02:30 AM

You could look at AudioSource.loop

The usage is pretty simple, if the game object already has an audio source component attached to it. You just call it like so, I suggest calling it in the "Start" function.

 audio.loop = true;

Should be as simple as that.

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 NCsoft · Jul 10, 2014 at 05:24 AM 0
Share

No No No ! You Code Error !

I need -> loop SoundBackground !

alt text

alt text

u1.png (31.3 kB)
u2.png (29.3 kB)
avatar image Flickayy · Jul 10, 2014 at 11:12 PM 0
Share

That's because you need an "Audio Source" component. This is where the sound comes from. Works fine for me.

It tells you clearly in the error message...

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how do i make footsteps only sound when i move in the area i place the audio? 1 Answer

how to start audioloop synced to one playing 1 Answer

How to make my music come on for a certain amount of time every few minutes 0 Answers

Audio source data? 0 Answers

Best way to play audio sound effects 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