Browse Source

Fixed sound + wait for end

master
Joshua Reason 4 years ago
parent
commit
07a57aa990
3 changed files with 111 additions and 9 deletions
  1. +71
    -1
      Assets/Scenes/CaseyTest.unity
  2. +38
    -6
      Assets/Scripts/Gameplay/AudioRandomiser.cs
  3. +2
    -2
      Assets/Scripts/Gameplay/GameStateController.cs

+ 71
- 1
Assets/Scenes/CaseyTest.unity View File

@ -4168,6 +4168,36 @@ PrefabInstance:
propertyPath: m_Name
value: LongSledgeHammer
objectReference: {fileID: 0}
- target: {fileID: 5460175760291139684, guid: 0cd2ef3ca51fc5541912dbdcd56cd066,
type: 3}
propertyPath: m_LocalRotation.x
value: -0.7071068
objectReference: {fileID: 0}
- target: {fileID: 5460175760291139684, guid: 0cd2ef3ca51fc5541912dbdcd56cd066,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5460175760291139684, guid: 0cd2ef3ca51fc5541912dbdcd56cd066,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5460175760291139684, guid: 0cd2ef3ca51fc5541912dbdcd56cd066,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 5460175760291139684, guid: 0cd2ef3ca51fc5541912dbdcd56cd066,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: -90
objectReference: {fileID: 0}
- target: {fileID: 5460175760291139684, guid: 0cd2ef3ca51fc5541912dbdcd56cd066,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0cd2ef3ca51fc5541912dbdcd56cd066, type: 3}
--- !u!4 &503616637 stripped
@ -6558,6 +6588,21 @@ PrefabInstance:
propertyPath: herd
value:
objectReference: {fileID: 1457452760}
- target: {fileID: 4035834407651339497, guid: 6ad2be9300e66ea46bc90805f007dd81,
type: 3}
propertyPath: spacialBlend
value: 0.022
objectReference: {fileID: 0}
- target: {fileID: 4035834407651339497, guid: 6ad2be9300e66ea46bc90805f007dd81,
type: 3}
propertyPath: volumes.Array.data[0]
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4035834407651339497, guid: 6ad2be9300e66ea46bc90805f007dd81,
type: 3}
propertyPath: volumes.Array.data[1]
value: 0.75
objectReference: {fileID: 0}
- target: {fileID: 4035834407651339498, guid: 6ad2be9300e66ea46bc90805f007dd81,
type: 3}
propertyPath: m_LocalPosition.x
@ -6618,6 +6663,31 @@ PrefabInstance:
propertyPath: audioPosition
value:
objectReference: {fileID: 963194225}
- target: {fileID: 4035834407651339499, guid: 6ad2be9300e66ea46bc90805f007dd81,
type: 3}
propertyPath: volumes.Array.data[0]
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4035834407651339499, guid: 6ad2be9300e66ea46bc90805f007dd81,
type: 3}
propertyPath: volumes.Array.data[1]
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4035834407651339499, guid: 6ad2be9300e66ea46bc90805f007dd81,
type: 3}
propertyPath: waitTime
value: 10
objectReference: {fileID: 0}
- target: {fileID: 4035834407651339499, guid: 6ad2be9300e66ea46bc90805f007dd81,
type: 3}
propertyPath: makeSolo
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4035834407651339499, guid: 6ad2be9300e66ea46bc90805f007dd81,
type: 3}
propertyPath: spacialBlend
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4035834407651339503, guid: 6ad2be9300e66ea46bc90805f007dd81,
type: 3}
propertyPath: m_Name
@ -13565,7 +13635,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2009130163}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.7, y: 8, z: 65.3}
m_LocalPosition: {x: 0.1, y: 2.9, z: 57}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1457452761}

+ 38
- 6
Assets/Scripts/Gameplay/AudioRandomiser.cs View File

@ -14,10 +14,16 @@ public class AudioRandomiser : MonoBehaviour
public float waitTime;
public float[] volumes;
public bool makeSolo;
public bool mute;
[Range(0, 1)]
public float spacialBlend = 1;
// Start is called before the first frame update
void Start()
{
}
void Awake()
@ -30,7 +36,7 @@ public class AudioRandomiser : MonoBehaviour
int count = 1;
if (herd != null)
{
count = (int) Mathf.Round(herd.HerdAmount() / 10);
count = (int)Mathf.Round(herd.HerdAmount() / 10);
count = Mathf.Clamp(count, 1, 10);
}
@ -47,19 +53,45 @@ public class AudioRandomiser : MonoBehaviour
yield return new WaitForSeconds(wait);
AudioClip clip = audioSources[Random.Range(0, audioSources.Length)];
float volume = Random.Range(volumes[0], volumes[1]);
AudioSource.PlayClipAtPoint(clip, audioPosition.transform.position, volume);
PlayClipAt(clip, Vector3.zero, (!mute) ? volume : 0);
if (makeSolo)
{
foreach (AudioRandomiser audioRandomiser in FindObjectsOfType<AudioRandomiser>())
if (audioRandomiser != this)
audioRandomiser.mute = true;
GetComponent<AudioSource>().volume /= 2f;
yield return new WaitForSeconds(clip.length);
GetComponent<AudioSource>().volume *= 2f;
foreach (AudioRandomiser audioRandomiser in FindObjectsOfType<AudioRandomiser>())
if (audioRandomiser != this)
audioRandomiser.mute = false;
}
}
public IEnumerator PlayClips()
{
yield return new WaitForSeconds(waitTime);
PlaySoundFromCount();
StartCoroutine(PlayClips());
}
// Update is called once per frame
void Update()
AudioSource PlayClipAt(AudioClip clip, Vector3 pos, float volume)
{
GameObject tempGO = new GameObject("TempAudio"); // create the temp object
tempGO.transform.position = pos; // set its position
AudioSource aSource = tempGO.AddComponent<AudioSource>(); // add an audio source
aSource.clip = clip; // define the clip
// set other aSource properties here, if desired
aSource.volume = volume;
aSource.spatialBlend = spacialBlend;
aSource.Play(); // start the sound
Destroy(tempGO, clip.length); // destroy object after clip duration
return aSource; // return the AudioSource reference
}
}

+ 2
- 2
Assets/Scripts/Gameplay/GameStateController.cs View File

@ -28,7 +28,7 @@ public class GameStateController : MonoBehaviour
StartCoroutine(FadeImage(WinLose.GetComponentInChildren<Image>()));
WinText.SetActive(true);
StartCoroutine(WaitForLoadOut());
SceneManager.LoadScene(0);
}
public void LoseState()
@ -39,7 +39,6 @@ public class GameStateController : MonoBehaviour
StartCoroutine(FadeImage(WinLose.GetComponentInChildren<Image>()));
LoseText.SetActive(true);
StartCoroutine(WaitForLoadOut());
SceneManager.LoadScene(0);
}
public IEnumerator FadeImage(Image img)
@ -55,6 +54,7 @@ public class GameStateController : MonoBehaviour
public IEnumerator WaitForLoadOut()
{
yield return new WaitForSeconds(5.0f);
SceneManager.LoadScene(0);
}
// Update is called once per frame

Loading…
Cancel
Save