- Home /
Question by
manysmokingmonkeys · Sep 27, 2021 at 02:32 PM ·
c#audio
how can i destroy only 1 instance of audio source Game object when there are 2,how to destroy only 1 instance of audio source Game object when there are 2
how can i destroy only 1 instance of audio source Game object when there are 2 right now my code will destroy both
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class DoNotDestroy : MonoBehaviour
{
public Scene currentScene;
public string currentSceneString;
public string WhatMusicToKill;
public string DontLoadMusicScene1;
public string DontLoadMusicScene2;
private void Update()
{
currentSceneString = SceneManager.GetActiveScene().name;
GameObject[] musicObj = GameObject.FindGameObjectsWithTag(WhatMusicToKill);
if (musicObj.Length > 1)
{
Destroy(this.gameObject);
}
if (currentSceneString == DontLoadMusicScene1)
{
Destroy(this.gameObject);
}
else if (currentSceneString == DontLoadMusicScene2)
{
Destroy(this.gameObject);
}
else
{
DontDestroyOnLoad(this.gameObject);
}
}
}
,how can i destroy only 1 instance of audio source Game object when there are 2 right now my code will destroy both
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class DoNotDestroy : MonoBehaviour
{
public Scene currentScene;
public string currentSceneString;
public string WhatMusicToKill;
public string DontLoadMusicScene1;
public string DontLoadMusicScene2;
private void Update()
{
currentSceneString = SceneManager.GetActiveScene().name;
GameObject[] musicObj = GameObject.FindGameObjectsWithTag(WhatMusicToKill);
if (musicObj.Length > 1)
{
Destroy(this.gameObject);
}
if (currentSceneString == DontLoadMusicScene1)
{
Destroy(this.gameObject);
}
else if (currentSceneString == DontLoadMusicScene2)
{
Destroy(this.gameObject);
}
else
{
DontDestroyOnLoad(this.gameObject);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers