Hello i have a problem my script play AudioSource more and more times … does anyone know why?
Here is my script :
sing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OpenDoorBoolean : MonoBehaviour
{
public float rotateR;
public float rotateL;
public float stoprotate = 80;
public bool openDoorBool = false;
public AudioSource OpenDoor;
public GameObject Ldoor;
public GameObject Rdoor;
public Transform camera;
public GameObject Spawn;
public bool camerabool = false;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (openDoorBool == true)
{
rotateR += 1 * Time.deltaTime * 50;
rotateL -= 1 * Time.deltaTime * 50;
Ldoor.transform.rotation = Quaternion.Euler(0, rotateL, 0);
Rdoor.transform.rotation = Quaternion.Euler(0, rotateR, 0);
if (camerabool == true && OpenDoor.isPlaying == false)
{
camerabool = false;
OpenDoor.Play();
StartCoroutine(cameraspawn());
}
}
if (rotateR > stoprotate)
{
openDoorBool = false;
}
IEnumerator cameraspawn()
{
yield return new WaitForSeconds(0.5f);
Instantiate(camera, Spawn.transform.position, Spawn.transform.rotation);
}
}
}