Audio for some of the machines

This commit is contained in:
Daniel Tyomin
2024-08-19 19:19:41 +02:00
parent 2aae4ce4a1
commit a6682a2b8b
19 changed files with 312 additions and 821 deletions

View File

@@ -2,7 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ConveyorBelt : MonoBehaviour
public class ConveyorBelt : MonoBehaviour, IResetable
{
Rigidbody _rb;
Rigidbody rb { get { if (!_rb) _rb = GetComponent<Rigidbody>(); return _rb; } }
@@ -15,8 +15,30 @@ public class ConveyorBelt : MonoBehaviour
public float scrollingTextureSpeedMult = 1;
public Renderer scrollingTextureRenderer;
public AudioClip conveyorClip;
public float volume = 0.25f;
private AudioSource _audioSource;
public void ResetMachine()
{
if (_audioSource)
{
_audioSource.Stop();
Destroy(_audioSource.gameObject);
_audioSource = null;
}
if (isActiveAndEnabled)
{
_audioSource = NAudio.Play(conveyorClip, transform.position, volume);
_audioSource.loop = true;
}
}
private void Start()
{
ResetMachine();
startPosition = rb.position;
//scrollingTextureSpeedMult = -0.1625f * speed;

View File

@@ -33,7 +33,6 @@ public class StagingManager: MonoBehaviour
foreach (var stageProp in FindObjectsOfType<StageProp>(true))
{
Debug.Log(stageProp.ActiveAtStages.HasFlag(stage));
stageProp.gameObject.SetActive(stageProp.ActiveAtStages.HasFlag(stage));
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
public class Converter: MonoBehaviour, IResetable
{
@@ -17,6 +18,9 @@ public class Converter: MonoBehaviour, IResetable
public float conversionDuration = 5f;
private float _conversionTimer;
[FormerlySerializedAs("conversionSound")] public AudioClip conversionClip;
private AudioSource _audioSource;
public Transform refuseLauncher;
public float launchPower = 10f;
@@ -42,6 +46,13 @@ public class Converter: MonoBehaviour, IResetable
CurrentHealth = MaxHealth;
inputProducts.Clear();
if (_audioSource)
{
_audioSource.Stop();
Destroy(_audioSource.gameObject);
_audioSource = null;
}
}
public void Update()
@@ -65,6 +76,8 @@ public class Converter: MonoBehaviour, IResetable
Spawner.SpawnProduct(conversionProduct, currentProduct.Defect);
inputProducts.RemoveAt(0);
Destroy(currentProduct);
_audioSource = NAudio.Play(conversionClip, transform.position, 0.75f);
}
else
{