Answers for "pause audio unity"

C#
5

pause audio unity

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


public AudioSource MyAudioSource; //put your object in inspector that have the audio


void Update(){


if (Input.GetKeyDown(KeyCode.Escape)) //When press ESC to pause the game
        {
            if (Time.timeScale == 0)
            {
                MyAudioSource.Stop();
            }
            else
            {
                MyAudioSource.Play();
            }
        }
        
        }
Posted by: Guest on March-27-2022
0

audio source pause unity

using UnityEngine;[RequireComponent(typeof(AudioSource))]
public audioSource audioSource  = GetComponent<AudioSource>();

void Start();{
	audioSource.Pause();
}
Posted by: Guest on December-11-2021

C# Answers by Framework

Browse Popular Code Answers by Language