chunk 1: core gameplay scripts scenes runtime assets
This commit is contained in:
120
Assets/Scripts/Character Effects FX/CharacterSoundFXManager.cs
Normal file
120
Assets/Scripts/Character Effects FX/CharacterSoundFXManager.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CharacterSoundFXManager : MonoBehaviour
|
||||
{
|
||||
private AudioSource audioSource;
|
||||
[SerializeField]
|
||||
private AudioClip dropSound, punchSound, kickSound, whooshSound, blockSound, screamSound, punchFaceHitSound, punchBodyHitSound;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
if (audioSource == null)
|
||||
{
|
||||
Debug.LogError("AudioSource component missing on " + gameObject.name + ". Please add an AudioSource.");
|
||||
}
|
||||
// Warn if any AudioClip is not assigned
|
||||
if (dropSound == null) Debug.LogWarning("dropSound AudioClip not assigned in CharacterSoundFXManager on " + gameObject.name);
|
||||
if (punchSound == null) Debug.LogWarning("punchSound AudioClip not assigned in CharacterSoundFXManager on " + gameObject.name);
|
||||
if (kickSound == null) Debug.LogWarning("kickSound AudioClip not assigned in CharacterSoundFXManager on " + gameObject.name);
|
||||
if (whooshSound == null) Debug.LogWarning("whooshSound AudioClip not assigned in CharacterSoundFXManager on " + gameObject.name);
|
||||
if (blockSound == null) Debug.LogWarning("blockSound AudioClip not assigned in CharacterSoundFXManager on " + gameObject.name);
|
||||
if (screamSound == null) Debug.LogWarning("screamSound AudioClip not assigned in CharacterSoundFXManager on " + gameObject.name);
|
||||
if (punchFaceHitSound == null) Debug.LogWarning("punchFaceHitSound AudioClip not assigned in CharacterSoundFXManager on " + gameObject.name);
|
||||
if (punchBodyHitSound == null) Debug.LogWarning("punchBodyHitSound AudioClip not assigned in CharacterSoundFXManager on " + gameObject.name);
|
||||
}
|
||||
|
||||
public void PlayHitSound()
|
||||
{
|
||||
audioSource.clip = dropSound;
|
||||
setVolumeValue();
|
||||
audioSource.Play();
|
||||
Debug.Log("Playing Hit Sound");
|
||||
}
|
||||
|
||||
public void PlayPunchLightHitSound()
|
||||
{
|
||||
audioSource.clip = punchSound;
|
||||
setVolumeValue();
|
||||
audioSource.Play();
|
||||
Debug.Log("Playing Punch Light Hit Sound");
|
||||
}
|
||||
public void PlayPunchFaceHitSound()
|
||||
{
|
||||
audioSource.clip = punchFaceHitSound;
|
||||
setVolumeValue();
|
||||
audioSource.Play();
|
||||
Debug.Log("Playing Punch Face Hit Sound");
|
||||
}
|
||||
public void PlayBodyHitSound()
|
||||
{
|
||||
audioSource.clip = punchBodyHitSound;
|
||||
setVolumeValue();
|
||||
audioSource.Play();
|
||||
Debug.Log("Playing Body Hit Sound");
|
||||
}
|
||||
public void PlayKickSound()
|
||||
{
|
||||
audioSource.clip = kickSound;
|
||||
setVolumeValue();
|
||||
audioSource.Play();
|
||||
Debug.Log("Playing Kick Sound");
|
||||
}
|
||||
|
||||
public void PlayWhooshSound()
|
||||
{
|
||||
audioSource.clip = whooshSound;
|
||||
setVolumeValue();
|
||||
audioSource.Play();
|
||||
Debug.Log("Playing Whoosh Sound");
|
||||
}
|
||||
|
||||
public void PlayBlockSound()
|
||||
{
|
||||
audioSource.clip = blockSound;
|
||||
setVolumeValue();
|
||||
audioSource.Play();
|
||||
Debug.Log("Playing Block Sound");
|
||||
}
|
||||
|
||||
public void PlayScreamSound()
|
||||
{
|
||||
audioSource.clip = screamSound;
|
||||
setVolumeValue();
|
||||
audioSource.Play();
|
||||
Debug.Log("Playing Scream Sound");
|
||||
}
|
||||
|
||||
private float volumeValue;
|
||||
private GameSettings gameSettings;
|
||||
void setVolumeValue(){
|
||||
gameSettings = LoadGameSettings();
|
||||
volumeValue = gameSettings.SFXVolume_value;
|
||||
if (volumeValue <= 0f) volumeValue = 1f;
|
||||
audioSource.volume = volumeValue;
|
||||
Debug.Log($"[CharacterSoundFXManager] Loaded SFXVolume_value: {gameSettings.SFXVolume_value}, Applied: {audioSource.volume}");
|
||||
}
|
||||
|
||||
//Saving and Loading Game Settings
|
||||
#region
|
||||
private const string GameSettingsKey = "GameSettings";
|
||||
|
||||
public static void SaveGameSettings(GameSettings settings){
|
||||
string json = JsonUtility.ToJson(settings);
|
||||
PlayerPrefs.SetString(GameSettingsKey, json);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public static GameSettings LoadGameSettings(){
|
||||
if (PlayerPrefs.HasKey(GameSettingsKey))
|
||||
{
|
||||
string json = PlayerPrefs.GetString(GameSettingsKey);
|
||||
return JsonUtility.FromJson<GameSettings>(json);
|
||||
}
|
||||
return new GameSettings(); // Return default settings if none are saved
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9c750393abebea438a844bfe2b7d838
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
44
Assets/Scripts/Character Effects FX/CharacterVFXManager.cs
Normal file
44
Assets/Scripts/Character Effects FX/CharacterVFXManager.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CharacterVFXManager : MonoBehaviour
|
||||
{
|
||||
public GameObject punchHitFXPrefab;
|
||||
public GameObject kickHitFXPrefab;
|
||||
//public ParticleSystem block_FX;
|
||||
public GameObject blockFXPrefab;
|
||||
// Start is called before the first frame update
|
||||
|
||||
|
||||
public void playPunchEffect(GameObject fxLocation)
|
||||
{
|
||||
Vector3 hitFX_Pos = fxLocation.transform.position;
|
||||
GameObject hitFX = Instantiate(punchHitFXPrefab, hitFX_Pos, Quaternion.identity);
|
||||
StartCoroutine(destroyHitFX(hitFX));
|
||||
}
|
||||
|
||||
public void playKickEffect(GameObject fxLocation)
|
||||
{
|
||||
Vector3 hitFX_Pos = fxLocation.transform.position;
|
||||
|
||||
GameObject hitFX = Instantiate(kickHitFXPrefab, hitFX_Pos, Quaternion.identity);
|
||||
StartCoroutine(destroyHitFX(hitFX));
|
||||
}
|
||||
|
||||
public void playBlockEffect(GameObject fxLocation)
|
||||
{
|
||||
Vector3 blockFX_Pos = fxLocation.transform.position;
|
||||
GameObject blockFX = Instantiate(blockFXPrefab, blockFX_Pos, Quaternion.identity);
|
||||
StartCoroutine(destroyHitFX(blockFX));
|
||||
//block effect is destroyed by a script attached to it
|
||||
//block_FX.Play();
|
||||
}
|
||||
|
||||
//destroy instantiated prefab in 10 secs
|
||||
IEnumerator destroyHitFX(GameObject hitFX)
|
||||
{
|
||||
yield return new WaitForSeconds(1f);
|
||||
Destroy(hitFX);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a3e036266c38ca40928765cf5cc0944
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user