A
A
Arthur Petrin2019-05-22 18:50:29
Unity
Arthur Petrin, 2019-05-22 18:50:29

How to make the sound infinite when pressed?

I wrote a script so that when I click on a character it would play a sound but only 1 time
but I need it to play a sound endlessly until I click on it again and it turns off
Here is the Script itself:
using UnityEngine;
public class Sounds : MonoBehavior
{
public AudioClip din;
AudioSource audio;
void Start()
{
audio = GetComponent();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse1)) //set any button
here audio.PlayOneShot(din);
}
}
If someone fumbles in this, help ;)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2019-05-22
@NeYmExa

https://docs.unity3d.com/ScriptReference/AudioSour... - set Loop to true and use normal play.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question